Getting error 403 while generating Access Token

Bharathi352
Hi
I am trying to generate acess token .
Getting the below error :
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "POST /session/token HTTP/1.1" 403 None
kiteconnect.exceptions.TokenException: Invalid `checksum`.

My code is

import logging
from kiteconnect import KiteConnect

api_key = 'Key'
api_secret = 'secret'

kite = KiteConnect(api_key=api_key)
print("loginHere:", kite.login_url())

request_token =input("Enter Token:")
gen_ses = kite.generate_session(request_token, api_secret)
acc_token =gen_ses['access_token']

Please help
Bharathi
  • SRIJAN
    As stated in the error message,your checksum is invalid. Your api_key and api_secret are literally 'key' and 'secret'. Try with the actual api_key and api_secret provided when making an app on the developer console.

    It will work properly.
  • Bharathi352
    Hi Srijan

    After getting the access token . how will I initiate the kite in with out asking/regenerating the request token

    i am using

    kite = KiteConnect(api_key=api_key,access_token= access_token)

    Getting Error
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "GET /instruments HTTP/1.1" 200 1326165

    Thank you
  • SRIJAN
    SRIJAN edited June 2022
    You are not getting any error.
    Status code 200 means your request was successful.

    Refer the sample code on GitHub here:

    https://github.com/zerodha/pykiteconnect#api-usage

    You don't need to generate request_token and then access_token for each session. This is only needed once each day when you login.

    An access token is valid for one whole day(till 6 AM next day). After generating access token,you can save it in your local database.

    And use set_access_token as shown in the documentation ,or directly pass the access token when initializing Kite object as you are doing currently.

    Read more about login flow here:

    https://kite.trade/docs/connect/v3/user/
This discussion has been closed.