# 报错:OpenSSL.SSL.Error: [(‘SSL routines’, ‘tls_process_server_certificate’, ‘certificate verify failed’)]

完整错误

Traceback (most recent call last):
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\urllib3\contrib\pyopenssl.py", line 453, in wrap_socket
    cnx.do_handshake()
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\OpenSSL\SSL.py", line 1915, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\OpenSSL\SSL.py", line 1647, in _raise_ssl_error
    _raise_current_error()
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\OpenSSL\_util.py", line 54, in exception_from_error_queue
    raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\urllib3\connectionpool.py", line 594, in urlopen
    self._prepare_proxy(conn)
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\urllib3\connectionpool.py", line 805, in _prepare_proxy
    conn.connect()
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\urllib3\connection.py", line 344, in connect
    ssl_context=context)
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\urllib3\util\ssl_.py", line 344, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\urllib3\contrib\pyopenssl.py", line 459, in wrap_socket
    raise ssl.SSLError('bad handshake: %r' % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\requests\adapters.py", line 449, in send
    timeout=timeout
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\urllib3\connectionpool.py", line 638, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\urllib3\util\retry.py", line 398, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='user.qzone.qq.com', port=443): Max retries exceeded with url: /9998935 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "D:/zjf_workspace/自己测试用的/qq/寻找可以访问空间的QQ号.py", line 12, in <module>
    response = requests.get(url=url,headers=headers,verify=True)
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\requests\api.py", line 75, in get
    return request('get', url, params=params, **kwargs)
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\requests\api.py", line 60, in request
    return session.request(method=method, url=url, **kwargs)
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\requests\sessions.py", line 533, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\requests\sessions.py", line 646, in send
    r = adapter.send(request, **kwargs)
  File "C:\Users\wb-zjf497303\AppData\Roaming\Python\Python36\site-packages\requests\adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='user.qzone.qq.com', port=443): Max retries exceeded with url: /9998935 (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

网上搜索最终找到一个快速解决方法:
request请求加入参数verify=True即可。

response = requests.get(url=url,headers=headers,verify=True)