简体   繁体   English

Python3 MySQL SSL错误-mysql.connector

[英]Python3 MySQL SSL Error - mysql.connector

I have spent all day on this and cant figure it out. 我整天都花在这上面,无法弄明白。 I have no problems connecting to the remote server using python and the mysql.connector but when i try using SSL I get the following error: 我使用python和mysql.connector连接到远程服务器没有问题,但是当我尝试使用SSL时,我收到以下错误:

    Traceback (most recent call last):
      File "/usr/local/lib/python3.4/dist-packages/mysql/connector/network.py", line 384, in switch_to_ssl
         self.sock.do_handshake()
      File "/usr/lib/python3.4/ssl.py", line 804, in do_handshake
         self._sslobj.do_handshake()
    ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:600)

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
      File "./mysql_test.py", line 25, in <module>
         con = mysql.connector.connect(**config);
      File "/usr/local/lib/python3.4/dist-packages/mysql/connector/__init__.py", line 179, in connect
         return MySQLConnection(*args, **kwargs)
      File "/usr/local/lib/python3.4/dist-packages/mysql/connector/connection.py", line 95, in __init__
         self.connect(**kwargs)
      File "/usr/local/lib/python3.4/dist-packages/mysql/connector/abstracts.py", line 719, in connect
         self._open_connection()
      File "/usr/local/lib/python3.4/dist-packages/mysql/connector/connection.py", line 210, in _open_connection
         self._ssl)
      File "/usr/local/lib/python3.4/dist-packages/mysql/connector/connection.py", line 134, in _do_auth
         self._socket.switch_to_ssl(**ssl_options)
      File "/usr/local/lib/python3.4/dist-packages/mysql/connector/network.py", line 390, in switch_to_ssl
         errno=2055, values=(self.get_address(), _strioerror(err)))
    mysql.connector.errors.InterfaceError: 2055: Lost connection to MySQL server at '192.168.1.10:3306', system error: 1 [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:600)
  • system spec both servers: 系统规格两台服务器:
  • Debian 8.2 Debian 8.2
  • OpenSSL 1.0.1k 8 Jan 2015 OpenSSL 1.0.1k 2015年1月8日
  • mysql 5.7.X. mysql 5.7.X.
  • python3 python3
  • pip3 PIP3
  • mysql.connector = Connector/Python 2.1.3 mysql.connector = Connector / Python 2.1.3

I know the ssl connection works with php and cli mysql connections but i can't figure out how to get ssl to work properly. 我知道ssl连接适用于php和cli mysql连接,但我无法弄清楚如何让ssl正常工作。 I have also tried to change the ssl protocol in the mysql.connector network.py source. 我还尝试在mysql.connector network.py源中更改ssl协议。 I have also tried with and without use_pure flag. 我也尝试过使用和不使用use_pure标志。 Any help is greatly appreciated. 任何帮助是极大的赞赏。

the python source: python源码:

    import mysql.connector
     config = {
        'user' : 'uname', 
        'password' :'passwd', 
        'host' : '192.168.1.10',
        'database' : 'python',
        'ssl_ca' : '/etc/mysql/ssl/client/ca-cert.pem',
        'ssl_cert' : '/etc/mysql/ssl/client/client-cert.pem',
        'ssl_key' : '/etc/mysql/ssl/client/client-key.pem',
        'use_pure' : 'False'
    }
    con = mysql.connector.connect(**config);
    con.close();

I figured it out. 我想到了。 Needed to remove the ssl_key and ssl_cert connection arguments, and only supply the ssl_ca and it works like a charm. 需要删除ssl_key和ssl_cert连接参数,并且只提供ssl_ca,它就像一个魅力。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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