4

我正在使用 asyncpg 在 Heroku postgresql 中使用 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")

它运行良好,直到我收到 heroku 的电子邮件,建议我进行维护:
Maintenance (DATABASE_URL on myappname) is starting now. We will update you when it has completed.

然后出现了这个错误:

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

我试图寻求一些帮助,比如 putssl=True 但是出现了这个错误:

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

和放一样ssl="allow"

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

我该怎么做才能解决这个问题?

4

1 回答 1

1

使用此解决方案有效

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)

注意:您不需要使用评论中提到的任何证书,因为我们将 verify_mode 设置为不使用证书。

于 2021-03-16T06:33:54.130 回答