【问题标题】:asyncpg error: "no pg_hba.conf entry for host" in Herokuasyncpg 错误:Heroku 中的“主机没有 pg_hba.conf 条目”
【发布时间】:2020-09-15 02:07:31
【问题描述】:

我正在使用 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

我试图寻求一些帮助,比如把ssl=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"

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

【问题讨论】:

  • 您尝试过this issue 中提出的一些解决方案吗?
  • 是的,我尝试了这些解决方案但没有奏效
  • 您可以使用psqlpsycopg2 成功连接吗?
  • 用 psycopg2 是的,但不能用 asyncpg,仍然是同样的错误

标签: python ssl heroku discord.py asyncpg


【解决方案1】:

使用来自this 的解决方案有效。

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-06-11
    • 1970-01-01
    • 2020-07-29
    • 2014-09-19
    • 2020-05-19
    • 2010-11-27
    • 1970-01-01
    • 1970-01-01
    • 2015-10-18
    相关资源
    最近更新 更多