Just I used the above sample and 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 Traceback (most recent call last): File "D:/Project/Python/Back/trade_api.py", line 14, in data = kite.generate_session("rTY5X023***************", api_secret="l5ztkssp************") File "D:\Project\Python\venv\lib\site-packages\kiteconnect-3.7.4-py3.6.egg\kiteconnect\connect.py", line 232, in generate_session File "D:\Project\Python\venv\lib\site-packages\kiteconnect-3.7.4-py3.6.egg\kiteconnect\connect.py", line 701, in _post File "D:\Project\Python\venv\lib\site-packages\kiteconnect-3.7.4-py3.6.egg\kiteconnect\connect.py", line 766, in _request kiteconnect.exceptions.TokenException: Token is invalid or has expired.
You are using older version of Kite Connect. Follow latest KiteConnect documentation here.