Reputation: 649
I need to pass in a custom argument to SQLAlchemy's create_engine
function in order to SSL authorize my database connection with AWS RDS. here, here, and here it was recommended that I use SQLAlchemy's connect_args
to pass in my custom keyword argument. I tried:
engine = create_engine(os.environ['DB_URI'], connect_args={'ssla':'amazon-rds-ca-cert.pem'})
However, I the following TypeError, which is the same error other posters said connect_args
fixed for them:
TypeError: 'ssla' is an invalid keyword argument for this function
It seems like I'm doing this exactly right. I also tried passing the keyword arguments in the connection string:
mysql://name:password@localhost/test?sslca=amazon-rds-ca-cert.pem
And changing the names of the keyword arguments to exactly match the example in the sqlalchemy docs:
db = create_engine('mysql://name:password@localhost/test', connect_args = {'argument2':'bar'})
However, still no luck. It seems that the error is being thrown by MySQLdb in the error message, so perhaps it's an error there?
File "/Users/tobyweed/workspace/ftm/live-event-market/server/serverenv/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 411, in connect
return self.dbapi.connect(*cargs, **cparams)
File "/Users/tobyweed/workspace/ftm/live-event-market/server/serverenv/lib/python2.7/site-packages/MySQLdb/__init__.py", line 86, in Connect
return Connection(*args, **kwargs)
File "/Users/tobyweed/workspace/ftm/live-event-market/server/serverenv/lib/python2.7/site-packages/MySQLdb/connections.py", line 204, in __init__
super(Connection, self).__init__(*args, **kwargs2)
TypeError: 'ssla' is an invalid keyword argument for this function
However, I don't have MySQLdb installed, so it must be SQLAlchemy which is using it. I have the latest version of SQLAlchemy (1.2.8), so that can't be it.
Please help!
Upvotes: 2
Views: 11091
Reputation: 223152
The argument is being passed upstream, that is, to your mysql dbapi module - All sqlalchemy does is call the connect
function from the chosen module.
As you can see here https://dev.mysql.com/doc/connector-python/en/connector-python-connectargs.html sslca
is not a valid parameter to the connect
function - the correct parameter name would be ssl_ca
I think?
In other words, you have to find out how to do what you want with python-mysql directly, without using sqlalchemy at all - sqlalchemy is not the culprit here
Also you say
However, I don't have MySQLdb installed, so it must be SQLAlchemy which is using it.
SQLAlchemy is not a database, it doesn't connect to anything. It is only a layer, you have to provide a database module for it to use to connect to databases.
Upvotes: 3