【发布时间】:2018-05-16 12:41:09
【问题描述】:
我正在连接到 websocket 客户端并订阅一些流。但我不断收到此错误
"'WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason'"
我不知道原因。谷歌搜索问题但没有帮助。 我正在使用 websockets 包。下面是我的代码。
async def streaming_data(url):
headers = await gives_auth(auth_url)
print(headers)
try:
async with websockets.client.connect(url,extra_headers=headers) as websocket:
response = await websocket.recv()
print(response)
except websockets.exceptions.InvalidHandshake:
print('Exception raised when a handshake request or response is invalid.')
except websockets.exceptions.InvalidURI:
print('Exception raised when an URI isn’t a valid websocket URI.')
except websockets.exceptions.InvalidStatusCode:
print('Handshake responce status code is invalid')
except Exception as e:
print('Error in making the Websocket Connection!!')
print(e.args)
loop = asyncio.new_event_loop()
stream_url=""
streams = [loop.create_task(streaming_data(stream_url))]
loop.run_until_complete(asyncio.wait(streams))
我对此很陌生。感谢您的帮助。
【问题讨论】:
标签: python asynchronous websocket python-asyncio