Python: websockets.exceptions.ConnectionClosed ошибка при использовании request_html - PullRequest
0 голосов
/ 20 февраля 2019

Я использую библиотеку 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

, и код застревает там и не 'ничего не делай.Есть ли способ заставить код продолжить и обработать следующий URL в цикле for?

...