-
-
Notifications
You must be signed in to change notification settings - Fork 569
Closed
Labels
Description
I'm not sure how to fix this error:
Traceback (most recent call last):
File "/root/src/streamer/stocks_producer.py", line 44, in <module>
main()
File "/root/src/streamer/stocks_producer.py", line 40, in main
streamer.start()
File "/root/src/streamer/polygon_streamer.py", line 67, in start
self.loop.run_until_complete(asyncio.gather(*tasks))
File "uvloop/loop.pyx", line 1451, in uvloop.loop.Loop.run_until_complete
File "/root/src/streamer/polygon_streamer.py", line 47, in connect
raise Exception(error_message)
Exception: resetting connection: ()
103 - 2019-02-13 15:30:14,095 - streamer.polygon_streamer - ERROR - resetting connection: ('WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason',)
Traceback (most recent call last):
File "/opt/conda/lib/python3.7/site-packages/websockets/protocol.py", line 528, in transfer_data
msg = yield from self.read_message()
File "/opt/conda/lib/python3.7/site-packages/websockets/protocol.py", line 580, in read_message
frame = yield from self.read_data_frame(max_size=self.max_size)
File "/opt/conda/lib/python3.7/site-packages/websockets/protocol.py", line 645, in read_data_frame
frame = yield from self.read_frame(max_size)
File "/opt/conda/lib/python3.7/site-packages/websockets/protocol.py", line 710, in read_frame
extensions=self.extensions,
File "/opt/conda/lib/python3.7/site-packages/websockets/framing.py", line 100, in read
data = yield from reader(2)
File "/opt/conda/lib/python3.7/asyncio/streams.py", line 677, in readexactly
raise IncompleteReadError(incomplete, n)
asyncio.streams.IncompleteReadError: 0 bytes read on a total of 2 expected bytes
here is my code snippet, thank you!
async def connect(self):
while True:
async with websockets.connect(self.url, max_queue=8 * 2**10,) as websocket:
await websocket.send(json.dumps({"action": "auth", "params": self._api_key}))
await websocket.send(json.dumps({"action": "subscribe", "params": self._symbols_str}))
log.info("connected: {}".format(websocket.remote_address))
while(True):
try:
message_str = await asyncio.wait_for(websocket.recv(), timeout=self._timeout)
# await self.queue.put(message_str)
self.queue.put_nowait(message_str)
except asyncio.TimeoutError:
log.warn("timeout error - no data in {} seconds, pinging connection".format(self._timeout))
pong_waiter = await asyncio.wait_for(websocket.ping(data="keepalive"), timeout=self._timeout)
await asyncio.wait_for(pong_waiter, timeout=2 * self._timeout)
log.warn('ping/pong received, keeping connection alive...')
except Exception as e:
error_message = "resetting connection: {}".format(e.args)
log.error(error_message)
raise Exception(error_message)