![]() POSTGRES_CONNECTION_PORT = "1234" # Set this to the correct port! Mine is provided by DigitalOcean and it's NOT 1234ĭb_info = "host='%s' dbname='%s' user='%s' password='%s' sslmode='require' sslrootcert='%s' port='%s'" % (POSTGRES_DATABASE_HOST_ADDRESS, POSTGRES_DATABASE_NAME, POSTGRES_USERNAME, POSTGRES_PASSWORD, SSL_ROOT_CERT, POSTGRES_CONNECTION_PORT) SSL_ROOT_CERT = os.path.join(path_to_current_directory, relative_path_to_ssl_cert ) Path_to_current_directory = os.path.dirname(_file_) POSTGRES_PASSWORD = HOW TO (Relative Path Python): POSTGRES_DATABASE_HOST_ADDRESS = "your-database-name-do-user-12345678-0.b.db." This is what my test_database_connection.py script looks like: import psycopg2 My HOSTNAME is a URL from DigitalOcean, but yours might be an IP Address instead. Users/myusername/Desktop/M圜oolPythonProgram/database/ssl_certificate/database/ssl_certificate/ca-certificate.crt Users/myusername/Desktop/M圜oolPythonProgram/test_database_connection.pyĪnd my SSL certificate is in a directory which looks like: ![]() My python script is in a directory which looks like: I believe you could also set an environment variable as well, but in my example my SSL certificate will be in a subdirectory. If you need to connect to your PostgresSQL database with an SSL certificate using psycopg2, you'll need to put your certificate SSL certificate in a subdirectory of your python program, and then you can reference the certificate in your connection string.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |