Generating a listenkey using requests


This part of my code is working fine and I am able to print the data as and when it comes.

class InterfaceWS:
    def __init__(self, exchange_name="BINANCE") -> None:
        self.exchange_name = exchange_name

    def connect(self): = websockets.connect(END_POINTS[self.exchange_name]["SPOT"]["TEST"]["ws"])

    def subscribe(self, symbol="btcusdt"):
            json.dumps({"method": "SUBSCRIBE", "params": [f"{symbol}@bookTicker"],"id": 1,}))
        while True:
            response =
            print("tick\n", response)

However now i need to fetch user data and am unable to understand
#1 what is the purpose of a listenkey and
#2 how to get a listenkey from the api.

If you could kindly help me with some code that uses requests and not python-binance or python-binance-connector it would be very grateful.

Update: when i am trying to get new listenkey using Postman I am getting this error.
{"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."}

  1. this repo has python code using basic libraries, it should be helpful.

  2. listenkey is used a token to get user’s information by websocket.

  3. the document for creating the listenkey.