WebSocket连接已关闭:代码= 1006

时间:2018-05-16 12:41:09

标签: python asynchronous websocket python-asyncio

我正在连接到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))

我对此很新。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

1006是保留值,不得设置为a中的状态代码  端点Close 控制框架

指定用于 应用程序期望状态代码指示 连接异常关闭,例如,没有发送或 收到Close 控制框