Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Python connector TypeError: wrap_socket() got an unexpected keyword argument 'ciphers'

I am running into an issue with MySQL python connection.

Traceback (most recent call last):
  File "./expconfig.py", line 176, in <module>
    cnx = mysql.connector.connect(**config)
  File "/usr/lib/python2.6/site-packages/mysql/connector/__init__.py", line 179, in connect
    return MySQLConnection(*args, **kwargs)
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 95, in __init__
    self.connect(**kwargs)
  File "/usr/lib/python2.6/site-packages/mysql/connector/abstracts.py", line 728, in connect
    self._open_connection()
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 228, in _open_connection
    self._ssl)
  File "/usr/lib/python2.6/site-packages/mysql/connector/connection.py", line 150, in _do_auth
    ssl_options.get('cipher'))
  File "/usr/lib/python2.6/site-packages/mysql/connector/network.py", line 420, in switch_to_ssl
    ssl_version=ssl.PROTOCOL_TLSv1, ciphers=cipher)
TypeError: wrap_socket() got an unexpected keyword argument 'ciphers'

MySQL server has "ssl_diabled" , so the client doesn't need SSL connection. However it invokes

I have following,

  • Python : 2.6.6 MySql Python connector mysql-connector-python-2.1.7
  • OS : RHEL 6.6
  • MySQL server Server version : 5.7.17-enterprise-commercial-advanced

Code

try:
    flags = [ClientFlag.FOUND_ROWS,-ClientFlag.SSL]

    config = {
        'user' : 'ed30_user',
        'password' : 'mypassword',
        'host' : options.remHost,
        'database' : 'config',
        'client_flags': [-ClientFlag.SSL],
        'ssl_disabled' : False
    }

    cnx = mysql.connector.connect(**config)
    cur=cnx.cursor(dictionary=True)
like image 900
Sam Avatar asked Feb 10 '26 04:02

Sam


2 Answers

The reason for the error was that Pythong 2.6.6 has "ssl" module with different method signature than expected by the MysqlConnector version 2.1.7.

The MySQL web https://dev.mysql.com/doc/connector-python/en/connector-python-versions.html had in correct version table

I dropped back to connector version mysql-connector-python-2.0.5-1.el6.noarch.rpm and the error went away.

like image 52
Sam Avatar answered Feb 18 '26 15:02

Sam


just set 'ssl_disabled' : True if using config file or ssl_disabled='True' if your config is in arguments to mysql.connector.connect function

like image 38
Maxim Listukhin Avatar answered Feb 18 '26 16:02

Maxim Listukhin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!