![](/img/trans.png)
[英]Error: 'no pg_hba.conf entry for host' using Django with PostgreSQL?
[英]asyncpg error: "no pg_hba.conf entry for host" in Heroku
我正在使用 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 的 email 通知我進行維護之前,它一直運行良好:
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"
我該怎么做才能解決這個問題?
使用此解決方案有效。
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 設置為不使用證書。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.