如何解决Python 向 kube 上的 nginx 入口后面的服务请求 SSL 错误的版本号间歇性
我有一个在 kubernetes 上运行的服务,该服务使用集群 ip 公开端口 443 和一个公开此服务的 Nginx 入口(使用默认的自签名证书)。
该服务完全正常,我可以执行我通常使用该应用程序执行的所有操作,但是在使用 Python 请求时,由于 SSL 问题而无法发出请求时,我时不时会遇到此问题:
Traceback (most recent call last):
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/urllib3/connectionpool.py",line 706,in urlopen
chunked=chunked,File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/urllib3/connectionpool.py",line 382,in _make_request
self._validate_conn(conn)
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/urllib3/connectionpool.py",line 1010,in _validate_conn
conn.connect()
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/urllib3/connection.py",line 421,in connect
tls_in_tls=tls_in_tls,File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/urllib3/util/ssl_.py",line 429,in ssl_wrap_socket
sock,context,tls_in_tls,server_hostname=server_hostname
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/urllib3/util/ssl_.py",line 472,in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock,server_hostname=server_hostname)
File "/usr/lib/python3.6/ssl.py",line 407,in wrap_socket
_context=self,_session=session)
File "/usr/lib/python3.6/ssl.py",line 817,in __init__
self.do_handshake()
File "/usr/lib/python3.6/ssl.py",line 1077,in do_handshake
self._sslobj.do_handshake()
File "/usr/lib/python3.6/ssl.py",line 689,in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:852)
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/requests/adapters.py",line 449,in send
timeout=timeout
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/urllib3/connectionpool.py",line 756,in urlopen
method,url,error=e,_pool=self,_stacktrace=sys.exc_info()[2]
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/urllib3/util/retry.py",line 574,in increment
raise MaxRetryError(_pool,error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='host',port=443): Max retries exceeded with url: /v4/workflows/query-document/test/runs/ (Caused by SSLError(SSLError(1,'[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:852)'),))
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "/home/barmstrong/repos/amp/scripts/post_runs.py",line 14,in <module>
response = requests.post(WORKFLOW_URL,files=SOURCE_DATA,headers=HEADERS,verify=False,timeout=30,data={'tags': ['test1']})
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/requests/api.py",line 119,in post
return request('post',data=data,json=json,**kwargs)
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/requests/api.py",line 61,in request
return session.request(method=method,url=url,**kwargs)
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/requests/sessions.py",line 542,in request
resp = self.send(prep,**send_kwargs)
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/requests/sessions.py",line 655,in send
r = adapter.send(request,**kwargs)
File "/home/barmstrong/.virtualenvs/amp/lib/python3.6/site-packages/requests/adapters.py",line 514,in send
raise SSLError(e,request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='host',))
这很不寻常,因为实际上一天前它工作正常,如果我卸载入口控制器并重新安装它再次按预期工作。在遇到此错误之前,我的一两个帖子请求也将成功通过。我在我的请求发布请求中禁用了验证 SSL 请求。
response = requests.post(WORKFLOW_URL,data={'tags': ['test1']})
来自入口控制器 pod 的两个成功请求日志,然后是失败的一个(在我看到此错误之前偶尔会通过一两个):
10.100.1.1 - - [07/May/2021:10:24:19 +0000] "POST /v4/workflows/query-document/test/runs/ HTTP/1.1" 201 118 "-" "python-requests/2.25.1" 703 1.083 [amp-amp-server-443] [] 10.100.1.81:8884 118 1.083 201 8988570ca7d94698de30ae96dd0f0e85
10.0.0.39 - - [07/May/2021:10:24:20 +0000] "POST /v4/workflows/query-document/test/runs/ HTTP/1.1" 201 118 "-" "python-requests/2.25.1" 703 0.960 [amp-amp-server-443] [] 10.100.1.81:8884 118 0.961 201 9b66042a892cbb6d2c66563879734fef
10.0.0.39 - - [07/May/2021:10:24:20 +0000] "\x16\x03\x01\x02\x00\x01\x00\x01\xFC\x03\x031U\x81\xD1_ `\xB9\x13\xFD\xF4\xBEX\x03\xC1\x8D\xD7\xA2\x9A\xB0`" 400 150 "-" "-" 0 0.132 [] [] - - - - 3489cf9059d14dcb7be5051aa5d19fbc
有谁知道这里发生了什么以及为什么它最初有效但几天后请求失败?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。