ssl.sslerror:(“错误握手:syscallerror(54,'econnreset'),)

q3aa0525  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(306)

我正试图从一个url页面上获得一些评论,它在几天前运行良好,从昨天起就不再运行了。我将python脚本发送给我的朋友,他们可以在mac上运行相同的python文件,但在我自己的mac上发生了此错误。

Traceback (most recent call last):
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py", line 485, in wrap_socket
    cnx.do_handshake()
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/OpenSSL/SSL.py", line 1934, in do_handshake
    self._raise_ssl_error(self._ssl, result)
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/OpenSSL/SSL.py", line 1663, in _raise_ssl_error
    raise SysCallError(errno, errorcode.get(errno))
OpenSSL.SSL.SysCallError: (54, 'ECONNRESET')

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/urllib3/connectionpool.py", line 672, in urlopen
    chunked=chunked,
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/urllib3/connectionpool.py", line 376, in _make_request
    self._validate_conn(conn)
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/urllib3/connectionpool.py", line 994, in _validate_conn
    conn.connect()
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/urllib3/connection.py", line 360, in connect
    ssl_context=context,
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/urllib3/util/ssl_.py", line 370, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/urllib3/contrib/pyopenssl.py", line 491, in wrap_socket
    raise ssl.SSLError("bad handshake: %r" % e)
ssl.SSLError: ("bad handshake: SysCallError(54, 'ECONNRESET')",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/urllib3/connectionpool.py", line 720, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/urllib3/util/retry.py", line 436, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='appweb.lizhi.fm', port=443): Max retries exceeded with url: /live/comments?liveId=5188859099674684982&start=1625957008136&count=50 (Caused by SSLError(SSLError("bad handshake: SysCallError(54, 'ECONNRESET')")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "lizhi_alert.py", line 42, in <module>
    res = requests.get(url, headers = headers, verify = False, timeout = 5)
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/requests/api.py", line 75, in get
    return request('get', url, params=params,**kwargs)
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/requests/api.py", line 60, in request
    return session.request(method=method, url=url,**kwargs)
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/requests/sessions.py", line 533, in request
    resp = self.send(prep,**send_kwargs)
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/requests/sessions.py", line 646, in send
    r = adapter.send(request,**kwargs)
  File "/Users/sherry/.pyenv/versions/version376env/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='appweb.lizhi.fm', port=443): Max retries exceeded with url: /live/comments?liveId=5188859099674684982&start=1625957008136&count=50 (Caused by SSLError(SSLError("bad handshake: SysCallError(54, 'ECONNRESET')")))

这段代码几天前运行得很好,我不知道为什么它在我的mac上突然不起作用。我试图更改我的ip地址,忽略ssl验证并添加标头,但也失败了。
提前感谢您的帮助!

url=f"https://appweb.lizhi.fm/live/comments?liveId={liveid}&start={msg_time}&count=50"
    headers = {'User-Agent': "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"}
    res = requests.get(url, timeout = 5, headers = headers,verify = False)
    try:
        json_res = res.json()
    except Exception as e:
        print(f"Failed to read comments: {e}")
        print(res.text)
        continue

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题