How to make mysql connection requiring CA-CERT with sqlalchemy or SQLObject

I would like to connect to a MySQL database which requires ca-cert. I can do this with MySQLdb as shown below:

MySQLdb.connect(host = self.host, port = self.port, unix_socket = self.unix_socket, user = self.user, passwd = self.passwd, db = self.db, ssl = { 'cert': self.sslcert, 'key': self.sslkey, 'ca': self.sslca } 

How do I do the same in SQLAlchemy or SQLObject?

Thanks Peter

+6
source share
3 answers

create_engine () in SQLAlchemy has a connect_args parameter:

connect_args is a dictionary of options that will be passed directly to the DBAPIs connect() method as additional keyword arguments.

+3
source

To use SSL certificates with SQLAlchemy and MySQLdb, use the following python code:

 db_connect_string='mysql://<user>:<pswd>@<db server>:3306/<database>' ssl_args = {'ssl': {'cert':'/path/to/client-cert', 'key':'/path/to/client-key', 'ca':'/path/to/ca-cert'}} create_engine(db_connect_string, connect_args=ssl_args) 
+17
source

SQLObject (untested):

 from sqlobject.mysql import MySQLConnection connection = MySQLConnection( db=self.db, user=self.user, password=self.password, host=self.host, ssl_key=self.sslkey, ssl_cert=self.sslcert, ssl_ca=self.sslca, ) 
0
source

Source: https://habr.com/ru/post/900809/


All Articles