简体   繁体   中英

SqlAlchemy + psycopg2 using ssl certificate

So far I was using just psycopg2 to create my postgresql connection like

connection = psy.connect(host=self.host, port=self.port, dbname=self.database, user=self.user, password=os.environ.get('POSTGRES_READONLY_USER_PASSWORD'), sslmode=self.sslmode, sslrootcert=os.environ.get('CA_FILE_PATH'))

however seeing now that it is deprecated I wanted to switch to sqlalchmey + psycopg2. I am using a CA.pem certificate for ssl, which works fine in the old version

I tried

args = {
        'host' : self.host,
        'user' : self.user,
        'password' : os.environ.get('POSTGRES_READONLY_USER_PASSWORD'),    
        'port' : self.port,
        'dbname' : self.database,
        'sslmode' : 'require',
        'sslrootcert' : os.environ.get('CA_FILE_PATH')
        }

    engine = sqlalchemy.create_engine("postgresql+psycopg2://", connect_args=args)
    connection = engine.connect()

But I am getting an error

Exception has occurred: OperationalError
(psycopg2.OperationalError) connection to server at "postgres.amf" (10.10.10.20), port 5433 failed: certificate present, but not private key file "C:\Users\Administrator\AppData\Roaming/postgresql/postgresql.key"

Anyone knows how I can get this working without the additional private keys????

I had

'sslcert' : os.environ.get('CA_FILE_PATH')

which was supposed to be

'sslrootcert' : os.environ.get('CA_FILE_PATH')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM