Python向kube上nginx入口后面的服务请求SSL错误的版本号(间歇性)

2024-10-02 10:19:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我在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, url, 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', url, 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', 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)'),))

这是不寻常的,因为一天前,如果我卸载ingress控制器并重新安装,它就可以正常工作了。在遇到此错误之前,我的一个或两个post请求也将成功通过。我已在我的请求post请求中禁用了验证SSL请求

response = requests.post(WORKFLOW_URL, files=SOURCE_DATA, headers=HEADERS, verify=False, timeout=30, 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

有没有人知道这里发生了什么,以及为什么它最初可以工作,但几天后请求失败了


Tags: inpysslhomerequestlibpackagesline

热门问题