troubleshooting Question

Python script with password security?

Avatar of jisoo411
jisoo411 asked on
PythonScripting Languages
15 Comments3 Solutions1875 ViewsLast Modified:
Hello,

I'm writing a Python script that will connect to a postgresql database using the psycopg2 library.  I'm getting around it pretty well but one concern I have is that when connecting to the database host, I have to hard code the username and password into the connection statement.  I would prefer not to do this and would like to somehow refer to an external file for this information and import that user account info then construct the connection string.  That way at least the username/password combo wouldn't be directly visible when looking at the Python code.  Any help or alternative ideas would be very much appreciated.

Example of the psycopg2 connection statement:
import psycopg2

conn_string = "dbname='mydatabase' port='1234' user='joe_shmoe' password = 'joespassword' host='hostaddress.com'"
conn = psycopg2.connect(conn_string)

Thanks,
Glen
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 3 Answers and 15 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 15 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros