2

我正在使用以下requests_html库:

from requests_html import HTMLSession  


for url in urls:
    ...
    session = HTMLSession() 
    r = session.get(url)
    r.html.render() 
    ...

每隔一段时间我就会收到这个错误:

Future exception was never retrieved
future: <Future finished exception=ConnectionClosed('WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason',)>
Traceback (most recent call last):
  File "/abc/lib/python3.6/site-packages/websockets/protocol.py", line 674, in transfer_data
    message = yield from self.read_message()
  File "/abc/lib/python3.6/site-packages/websockets/protocol.py", line 742, in read_message
    frame = yield from self.read_data_frame(max_size=self.max_size)
  File "/abc/lib/python3.6/site-packages/websockets/protocol.py", line 815, in read_data_frame
    frame = yield from self.read_frame(max_size)
  File "/abc/lib/python3.6/site-packages/websockets/protocol.py", line 884, in read_frame
    extensions=self.extensions,
  File "/abc/lib/python3.6/site-packages/websockets/framing.py", line 99, in read
    data = yield from reader(2)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/asyncio/streams.py", line 666, in readexactly
    raise IncompleteReadError(incomplete, n)
asyncio.streams.IncompleteReadError: 0 bytes read on a total of 2 expected bytes

The above exception was the direct cause of the following exception:

websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason

并且代码卡在那里并且不做任何事情。有没有办法让代码继续并处理for循环中的下一个url?

4

0 回答 0