This is a problem of urllib3 (1.25).
Workaround is to use older version of it:
pip install -U "urllib3<1.25"
[2019-10-15 10:54:13,137] ERROR in app: Exception on /jscode2session [GET]
Traceback (most recent call last):
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 485, in wrap_socket
cnx.do_handshake()
File "/home/tianyxu/.local/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1915, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/home/tianyxu/.local/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1647, in _raise_ssl_error
_raise_current_error()
File "/home/tianyxu/.local/lib/python3.6/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 "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 672, in urlopen
chunked=chunked,
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 376, in _make_request
self._validate_conn(conn)
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn
conn.connect()
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/connection.py", line 394, in connect
ssl_context=context,
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 370, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py", line 491, 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 "/home/tianyxu/.local/lib/python3.6/site-packages/flask/app.py", line 2446, in wsgi_app
response = self.full_dispatch_request()
File "/home/tianyxu/.local/lib/python3.6/site-packages/flask/app.py", line 1951, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/usr/local/lib/python3.6/dist-packages/flask_cors/extension.py", line 161, in wrapped_function
return cors_after_request(app.make_response(f(*args, **kwargs)))
File "/home/tianyxu/.local/lib/python3.6/site-packages/flask/app.py", line 1820, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/tianyxu/.local/lib/python3.6/site-packages/flask/_compat.py", line 39, in reraise
raise value
File "/home/tianyxu/.local/lib/python3.6/site-packages/flask/app.py", line 1949, in full_dispatch_request
rv = self.dispatch_request()
File "/home/tianyxu/.local/lib/python3.6/site-packages/flask/app.py", line 1935, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/mnt/grimm_source/newGrimm/Grimm/server/main.py", line 94, in wx_jscode2session
response = http.request('GET', url)
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/request.py", line 76, in request
method, url, fields=fields, headers=headers, **urlopen_kw
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/request.py", line 97, in request_encode_url
return self.urlopen(method, url, **extra_kw)
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/poolmanager.py", line 330, in urlopen
response = conn.urlopen(method, u.request_uri, **kw)
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 762, in urlopen
**response_kw
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 762, in urlopen
**response_kw
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 762, in urlopen
**response_kw
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/connectionpool.py", line 720, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/home/tianyxu/.local/lib/python3.6/site-packages/urllib3/util/retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.weixin.qq.com', port=443): Max retries exceeded with url: /sns/jscode2session?appid=wx92cd67eef330384f&secret=354887ad67d17d87ea43fddbe719fd22&js_code=0616gHLq1INLbm03eyJq1PUGLq16gHLn&grant_type=authorization_code (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))
本文解决了一个在使用urllib3时遇到的SSL证书验证失败的问题,通过回退到urllib3的旧版本,成功避免了错误并使应用恢复正常运行。

4万+

被折叠的 条评论
为什么被折叠?



