0

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'"

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.

iamklaus
  • 3,720
  • 2
  • 12
  • 21

1 Answers1

0

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

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.

Andrew Svetlov
  • 16,730
  • 8
  • 66
  • 69