Does psycopg2 allow passing an existing SSL connection to psycopg2.connect()? #1420
Replies: 2 comments
-
Hello Jack, psycopg (2 and 3) use the libpq, the PostgreSQL client library, to connect to the database. I don't believe that the libpq offers such functionality. Maybe it's something that can be added, but it should be in the libpq; once it's available we would be happy to support it in psycopg. Something unbelievably brutal we could attempt on our side could be to sneak an ssl structure in the connection after the creation of the structure but before attempting connection to bypass this branch but it requires access to the PGconn structure internals, which are outside the public interface. ISTM that it's possible to add a new function to the libpq, which may be called between PQconnetStart and PQconnectPoll to initialise the ssl context from the outside (e.g. I would be open to work on the feature and to propose it upstream to the PostgreSQL developers, if the work has some financial support. |
Beta Was this translation helpful? Give feedback.
-
Closing the conversation as the ticket #1421 is probably more appropriate to work on. |
Beta Was this translation helpful? Give feedback.
-
The Cloud SQL Python Connector would like to support database connections to Cloud SQL using psycopg2. In order to do so we require the ability to pass in an existing connection or the ability to configure the connection level SSL.
Is this something that is currently possible with psycopg2?
For reference, we currently support pg8000 through the use of their
ssl_context
argument which allows us to pass in our pre-configured ssl.SSLContext object. pg8000 ssl_contextBeta Was this translation helpful? Give feedback.
All reactions