FrostySun

python链接https报错EOF occurred in violation of protocol (_ssl.c:1108)

Traceback (most recent call last):
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/urllib3/connectionpool.py", line 700, in urlopen
    self._prepare_proxy(conn)
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/urllib3/connectionpool.py", line 996, in _prepare_proxy
    conn.connect()
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/urllib3/connection.py", line 414, in connect
    self.sock = ssl_wrap_socket(
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/urllib3/util/ssl_.py", line 453, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/urllib3/util/ssl_.py", line 495, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ssl.py", line 1040, in _create
    self.do_handshake()
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/ssl.py", line 1309, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1108)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/requests/adapters.py", line 489, in send
    resp = conn.urlopen(
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/urllib3/connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/urllib3/util/retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='10.10.10.10', port=443): Max retries exceeded with url: /api/sys/page?pageNum=1&pageSize=9999 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1108)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/requests/api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/requests/sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/requests/sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "/Users/sunbo/Library/Python/3.8/lib/python/site-packages/requests/adapters.py", line 563, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='10.10.10.10', port=443): Max retries exceeded with url: /api/sys/page?pageNum=1&pageSize=9999 (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:1108)')))
  • 处理方式

## 在请求中添加`verify=False`以及`proxies={'http': prox, 'https': prox}`
prox = ''
    res = requests.get(url=url, proxies={'http': prox, 'https': prox}, headers=header, verify=False)