我花了一整天的时间在这上面,并且无法弄明白。使用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)
我知道ssl连接适用于php和cli mysql连接,但我无法弄清楚如何让ssl正常工作。我还尝试在mysql.connector network.py源中更改ssl协议。我也尝试过使用和不使用use_pure标志。任何帮助是极大的赞赏。
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();
答案 0 :(得分:0)
我明白了。需要删除ssl_key和ssl_cert连接参数,并且只提供ssl_ca,它就像一个魅力。