request token error

I am entering the correct request token, within a minute. I am still receiving the error "TokenException: Token is invalid or has expired."

I bought the api two days back and received the api key and api secret the same day. but the amount for my api and historical api deducted today.
  • rakeshr
    "TokenException: Token is invalid or has expired."
    Are you still facing issue?
    Go through the login FAQs here.
  • YBZ170
    I went through the FAQ, I get an error 403. I am entering the request token within a minute, have tried in multiple times and ensured that I am entering correct details. I have a question regarding the subscription too, is it possible to get api key and secret without amount getting deducted from my kite trading app?
  • sujith
    Nope, You need a Kite Connect app to create a session. You might have created a Kite Publisher app.
  • YBZ170
    YBZ170 edited May 18
    can you share a sample login code, so that i can check ?
  • YBZ170
    YBZ170 edited May 18
    this is the basic structure of what I'm using

    from kiteconnect import KiteConnect
    import webbrowser

    api_key = " "
    api_secret = " "

    # Initialize KiteConnect
    kite = KiteConnect(api_key=api_key)

    # Generate login URL and open it in a browser
    login_url = kite.login_url()
    print(f"Login URL: {login_url}")

    # Open the login URL in the browser

    # Prompt the user to enter the request token
    request_token = input("Enter the request token: ").strip()

    # Debugging: print the request token to ensure it's correct
    print(f"Request Token: {request_token}")

    # Generate access token using the request token and API secret
    data = kite.generate_session(request_token, api_secret)
    access_token = data["access_token"]
    print(f"Access Token: {access_token}")

    # Initialize the KiteConnect object with the access token

    # Make API calls
    profile = kite.profile()
    except Exception as e:
    print(f"Error: {e}")
  • sujith
    It is mandatory by the exchange that a user has to login manually at least once day. We don't recommend automating login.
This discussion has been closed.