SSL IP地址不匹配pymsql

时间:2019-06-27 18:08:41

标签: python ssl

我这样将我的SSL证书传递给了pymsql:

`conn = pymysql.connect(host='hostname', user='root', password='pass',ssl ={ 'cert':'client-cert.pem','key': 'client-key.pem','ca':'server-ca.pem'} )`

但是它抛出了这个错误:

Traceback (most recent call last):
 File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\site- 
 packages\pymysql\connections.py", line 599, in connect
 self._request_authentication()
 File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\site- 
 packages\pymysql\connections.py", line 803, in _request_authentication
 self._sock = self.ctx.wrap_socket(self._sock, server_hostname=self.host)
 File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\ssl.py", 
 line 412, in wrap_socket
 session=session
 File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\ssl.py", 
 line 853, in _create
 self.do_handshake()
 File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\ssl.py", 
 line 1117, in do_handshake
 self._sslobj.do_handshake()
 ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate 
 verify failed: IP address mismatch, certificate is not valid for 
'Hostname'. (_ssl.c:1056)

  During handling of the above exception, another exception occurred: 

 Traceback (most recent call last):
 File "D:/PythonProject/test.py", line 3, in <module>
 conn = pymysql.connect(host='hostname', user='root', 
 password='pass',ssl ={ 'cert':'client-cert.pem','key': 'client- 
 key.pem','ca':'server-ca.pem'} )
 File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\site- 
 packages\pymysql\__init__.py", line 94, in Connect
 return Connection(*args, **kwargs)
 File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\site- 
 packages\pymysql\connections.py", line 325, in __init__
 self.connect()
 File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\site- 
 packages\pymysql\connections.py", line 630, in connect
 raise exc
 pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 
 'Hostname' ([SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: IP 
  address mismatch, certificate is not valid for 'Hostname'. 
  (_ssl.c:1056))")

我想要的是通过SSL证书,以便我可以安全的方式连接到数据库

0 个答案:

没有答案