Issue
I am trying to connect to the Heroku Postgres database using the databases
python library in fastapi
.
Following is my code
import databases
import sqlalchemy
from fastapi import FastAPI
from pydantic import BaseModel
DATABASE_URL = "postgresql://user:password@postgresserver/db"
database = databases.Database(DATABASE_URL,ssl = True)
engine = create_engine(SQLALCHEMY_DATABASE_URL, pool_pre_ping=True,)
Base = declarative_base()
Base.metadata.create_all(database.engine)
...
On running it shows the following error:
self._sslobj.do_handshake()
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:1108)
I want to use databases
to use the async feature in fastapi
. Please help
Solution
I'm not familiar with Heroku platform so I don't know if they just simply use self signed certificates for database connectivity but if you're sure that you trust this cert you can create a new SSL context and disable verification:
import ssl
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
database = databases.Database(DATABASE_URL, ssl=ctx)
...
Answered By - HTF
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.