WebSocket连接已关闭:代码= 1006 [英] WebSocket connection is closed: code = 1006

查看:147
本文介绍了WebSocket连接已关闭:代码= 1006的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在连接到Websocket客户端并订阅一些流.但是我不断收到这个错误

I am connecting to a websocket client and subscribing to some streams. But I keep on getting this error

"'WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason'"

我不知道原因.搜索问题,但没有帮助.我正在使用websockets包.下面是我的代码.

I don't know the reason. Googled the problem but no help. I am using websockets package. Below is my code.

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))

我对此很陌生.感谢您的帮助.

I am fairly new to this. Thanks for the help.

推荐答案

1006 是保留值,并且不得在 Close 控制框架.

1006 is a reserved value and MUST NOT be set as a status code in a Close control frame by an endpoint.

指定用于要求状态代码指示以下内容的应用程序:连接异常关闭,例如,没有发送或收到 Close 控制框.

It is designated for use in applications expecting a status code to indicate that the connection was closed abnormally, e.g., without sending or receiving a Close control frame.

这篇关于WebSocket连接已关闭:代码= 1006的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆