Python3 MySQL SSL错误-MySQL.connector
我花了一整天的时间在这上面,弄不明白。我使用python和mysql.connector连接到远程服务器没有问题,但是当我尝试使用SSL时,我得到以下错误:Python3 MySQL SSL错误-MySQL.connector,python,mysql,ssl,Python,Mysql,Ssl,我花了一整天的时间在这上面,弄不明白。我使用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_han
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)
我想出来了。需要删除ssl_密钥和ssl_证书连接参数,并且只提供ssl_ca,它就像一个符咒
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();