"Common name is not known" when connecting with psycopg2
Hello,
I'm trying to get psycopg2 to connect to my database. This is what my call to psycopg2.connect looks like:
connectstring = "postgresql://[USER]:[PASSWORD]@eu-central-1.aws.neon.tech/[DB]"
url = up.urlparse(connectstring) params = {'sslmode': 'require', 'options': 'endpoint=[ENDPOINT]'} connection = psycopg2.connect( database=url.path[1:], user=url.username, password=url.password, host=url.hostname, port=url.port, **params ) The error I'm getting is: psycopg2.OperationalError: connection to server at "eu-central-1.aws.neon.tech" ([IP]), port 5432 failed: ERROR: Common name inferred from SNI ('aws.neon.tech') is not known. I am able to connect to psql using the connection string (including the query parameters) but I'm not sure why psycopg2 won't connect.
url = up.urlparse(connectstring) params = {'sslmode': 'require', 'options': 'endpoint=[ENDPOINT]'} connection = psycopg2.connect( database=url.path[1:], user=url.username, password=url.password, host=url.hostname, port=url.port, **params ) The error I'm getting is: psycopg2.OperationalError: connection to server at "eu-central-1.aws.neon.tech" ([IP]), port 5432 failed: ERROR: Common name inferred from SNI ('aws.neon.tech') is not known. I am able to connect to psql using the connection string (including the query parameters) but I'm not sure why psycopg2 won't connect.
3 Replies
harsh-harlequin•2y ago
That's a new one. Interesting
Oh right. You need to out the endpoint in the connection string
[ENDPOINT].eu-central-1.aws.neon.techpassive-yellowOP•2y ago
Thanks. It's now working. I had removed it from there previously because I was told to add it as a query parameter so thought it shouldn't go in two places.
By the way, I'm pretty sure this is the quickest useful answer to a support query I have ever gotten. Well done 🙂
harsh-harlequin•2y ago
:chefskiss: