[Python] Send headers in Websockets connection request from Python client

Discussão em 'Python' iniciado por Stack, Novembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    What is the correct method / syntax for adding headers to a websocket connection request using Python Websockets ?

    The server I'm trying to connect to requires headers in the connection request for authentication

    async def connect():
    async with websockets.connect("wss://site.com/ws") as websocket:
    response = await websocket.recv()
    print(response)

    # eg. does not work:
    async with websockets.connect(f"wss://site.com/ws, header={headers}") as websocket:
    async with websockets.connect(f"wss://site.com/ws, extra_headers:{headers}") as websocket:


    Similar question was asked here but did not answer the core of the question: How to send 'Headers' in websocket python

    Continue reading...

Compartilhe esta Página