Invalid checksum while generating access token using Python Kite Connect 5.2.1

rasikrajworld
I am trying to develop a desktop application using Kite Connect to download NSE/NFO options data.

I have created a Kite Connect app and am using the official Python Kite Connect library.

Environment:

Python: 3.14 (64-bit)
Kite Connect Python package: 5.2.1
Operating system: Windows
Application type: Local/desktop Python application
Kite Connect app status: Active
Redirect URL: http://127.0.0.1

Login flow:

I generate the Kite login URL using kite.login_url().
I open the URL and successfully log in to my Zerodha account.
Zerodha successfully redirects to my local Flask server at http://127.0.0.1.
My Flask application successfully receives the request_token.
I then call:
data = kite.generate_session(
request_token,
api_secret=API_SECRET
)
The request reaches Kite Connect, but I consistently receive:
Invalid `checksum`

What I have already checked:

The Kite Connect app is active.
The API Key and API Secret are from the same Kite Connect application.
The API Key is being read correctly by Python.
The API Secret is being read correctly by Python.
API Key length is 16 characters.
API Secret length is 32 characters.
I regenerated the API Secret and updated it in the Python program.
I generated a fresh request token for each login attempt.
I am not reusing an old request token.
The Python SDK's generate_session() function is being used directly; I am not manually modifying the checksum.
I checked the installed SDK source code, and it calculates the checksum as:
SHA256(API_KEY + REQUEST_TOKEN + API_SECRET)

The relevant SDK code is:

h = hashlib.sha256(
self.api_key.encode("utf-8") +
request_token.encode("utf-8") +
api_secret.encode("utf-8")
)


checksum = h.hexdigest()

The Flask server confirms that the redirect is successful and receives the request token:

GET /?action=login&type=login&status=success&request_token=... HTTP/1.1
200

However, the subsequent generate_session() call always returns:

TokenException: Invalid `checksum`

Could you please help me identify why the checksum is being rejected despite:

an active Kite Connect app,
correct API Key/API Secret being used,
fresh request tokens,
successful Zerodha login and redirect, and
the official Kite Connect Python SDK 5.2.1 generating the checksum?

I have intentionally not included my API Key, API Secret, request token, or access token for security reasons.

Thank you.
  • Nivas
    It means either your api_key or api_secret or request token is wrong. We verified and there is no issue with Python SDK.

    You could try generating the access token using a standalone login script instead of your application. This can help isolate whether the issue is related to the credentials or the application flow.
  • sram
    I followed the suggested standalone login-script test.

    The standalone Python script using Kite Connect SDK 5.2.1 also fails during generate_session().

    API key length: 16
    API secret length: 32
    Request token length: 32
    Request token has no whitespace
    API key and API secret match the active app
    API secret was regenerated
    Fresh request token is used immediately

    The standalone SDK call returns:

    TokenException: Invalid checksum

    The direct /session/token request also returns HTTP 403:

    {"status":"error","error_type":"TokenException","message":"Invalid checksum."}

    Please check whether there is an issue with the newly created Kite Connect app/session authentication on the server side.

    Thanks,
    Siva
  • salim_chisty
    We have checked and verified this at our end. There are no issues in generating the request token and access token for the newly created app.

    Please follow the login flow as outlined in the Kite Connect API documentation. For further guidance, you can refer to this webinar.
  • sram
    Hi, I followed the login flow from the Kite Connect v3 documentation and the Zerodha webinar as suggested.

    I also tested the authentication independently using a standalone Python script with Kite Connect SDK 5.2.1, without involving my backtester.

    The flow is:

    Generate the login URL using the current API key.
    Login to Kite and complete 2FA.
    Receive a fresh request_token from the registered redirect URL.
    Immediately pass that request token to kite.generate_session(request_token, api_secret).

    The credentials have been verified against the Developer Console:

    API key length: 16
    API secret length: 32
    No leading/trailing whitespace
    API secret was regenerated and verified
    Fresh request token length: 32

    However, the standalone SDK call returns:

    TokenException: Invalid checksum

    I also tested the /session/token endpoint directly and received HTTP 403 with the same Invalid checksum error.

    Could you please advise what I should check next on the Kite Connect app/account side?

    I have not changed the redirect URL from Google yet. If you recommend using a localhost callback for this authentication flow, I can change it and test that as well.

    Thanks,
    Siva
Sign In or Register to comment.