asyncpg 错误:Heroku 中“没有主机的 pg_hba.conf 条目”

Luc*_*sch 5 python ssl heroku asyncpg discord.py

我正在使用 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")
Run Code Online (Sandbox Code Playgroud)

它一直工作得很好,直到我收到了来自 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
Run Code Online (Sandbox Code Playgroud)

我尝试遵循一些帮助,例如 putssl=True 但出现此错误:

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1108)
Run Code Online (Sandbox Code Playgroud)

和放一样ssl="allow"

asyncpg.exceptions.InvalidPasswordError: password authentication failed for user "xxx"
Run Code Online (Sandbox Code Playgroud)

我能做什么来解决这个问题?

Cer*_*res 1

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)
Run Code Online (Sandbox Code Playgroud)

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