2

I am trying to create a connection to a Heroku PostgreSQL database via Python. I am using Windows10 with Python 3.6.8 and PostgreSQL 9.6.

I took this piece of code from "http://andyfiedler.com/2016/10/connecting-to-heroku-postgres-in-python"

import psycopg2

import subprocess

proc = subprocess.Popen('heroku config:get DATABASE_URL -a heroku_app', stdout=subprocess.PIPE, shell=True)
db_url = proc.stdout.read().decode('utf-8').strip() + '?sslmode=require'
heroku_conn = psycopg2.connect(db_url)

When I run that code, I get the error:

OperationalError: could not create SSL context: No such process

Searching around suggests that I need to install PostgreSQL with the "--with-openssl" option. Or, with SSL compiled in.

How do I do this in Windows10? Or, is there another way to get this to work? Thank you!

1 Answer 1

1

PostgreSQL's client library, named “libpq”, has optional support for SSL. You need the programs that will connect to PostgreSQL, to have that support enabled when the program was built.

You can get the official PostgreSQL packages for Windows.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your help. Those links ended up leading me to a solution, although not what I expected. What worked for me was to uninstall the Anaconda version of psycopg2 and reinstall via "pip install psycopg2". The pip version is slightly newer at 2.7.7 compared to the Anaconda version at 2.7.6.1.
I can confirm the previous comment by @ochaer1. My error was psycopg2.OperationalError, mentioning that the PostgreSQL config tables had no entry for user {user} @ location {IP} on database {db} with Use SSL = false. The cause was a SSL connection set mandatory on the server. PIP version of psycopg2 does support SSL, Conda version did not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.