0

I am trying to make a connection using Web sockets Client API. For making the connection, a "Play Session" cookie needs to be passed for verifying the user.

Following is my code:

async def streaming_data(url, play_session):
    try:
        async with websockets.connect(url) as websocket:
            response = await websocket.recv()
            data = reponse.read()
    except Exception as e:
        print('Error in making the Websocket Connection!!')
        print(e.args)

    print(data) 

Note: Play Session is the cookie.

I am getting the error : "Status code not in 101:403" I am using websockets library for making the connection.

I'm a beginner, so any help would be much appreciated.

1 Answers1

1

In order to send a cookie while connecting to websocket server, you have to pass cookie HTTP header to connect() function.

You haven't specified the format of data in your play_session variable. So we suppose that you are required to send cookie which has name play_session and value 100:

cookie = 'play_session=100'
headers = {'Cookie': cookie}

async with websockets.connect(url, extra_headers=headers) as websocket:
    ...
Andrii Maletskyi
  • 2,152
  • 1
  • 15
  • 24