asyncpg error: "no pg_hba.conf entry for host" in Heroku

Viewed 1256

I'm using asyncpg to connect my database in Heroku postgresql, using python:

import asyncpg

async def create_db_pool():
   bot.pg_con = await asyncpg.create_pool(dsn="postgres://....", host="....amazonaws.com", user="xxx", database="yyy", port="5432", password="12345")

it was working perfectly until I received an email from heroku advising me of a maintenance:
Maintenance (DATABASE_URL on myappname) is starting now. We will update you when it has completed.

then this error appeared:

asyncpg.exceptions.InvalidAuthorizationSpecificationError: no pg_hba.conf entry for host "123.456.789.10", user "xxx", database "yyy", SSL off

I tried to follow some help, like putting ssl=True but this error appeared:

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1108)

same as putting ssl="allow"

asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "xxx"

what can I do to fix this?

1 Answers

Using the solution from this worked.

import ssl
ssl_object = ssl.create_default_context()
ssl_object.check_hostname = False
ssl_object.verify_mode = ssl.CERT_NONE
# connect elsewhere
pool = await asyncpg.create_pool(uri, ssl=ssl_object)

Note: You don't need to use any certificate like mentioned in the comment, as we set verify_mode to not use certificates.

Related