exception while placing the order-InputException: Invalid `api_key` or `access_token`

svprasad
I followed below steps but getting exception InputException: Invalid `api_key` or `access_token` inspite of multiple times repeating below steps

api_key='xxx' -- from app
api_secret='yyy' -- from app
kite=KiteConnect(api_key,api_secret)
kite.login_url()
https://kite.trade/connect/login?api_key=xxxx&v=3

---https://kite.trade/?request_token=Kzzzzzg&action=login&status=success

data = kite.generate_session('Kzzzzzg',api_secret) --Kzzzzzg is request_token from url

kite.set_access_token('ppppppppp') -- ppp is access_token
kite.place_order(tradingsymbol='SBIN',quantity=1,exchange='NSE',order_type='MARKET',transaction_type='BUY',product='CNC',variety='REGULAR')

exception trace

ite.place_order(tradingsymbol='SBIN',quantity=1,exchange='NSE',order_type='MARKET',transaction_type='BUY',product='CNC',variety='REGULAR')
Traceback (most recent call last):

File "", line 1, in
kite.place_order(tradingsymbol='SBIN',quantity=1,exchange='NSE',order_type='MARKET',transaction_type='BUY',product='CNC',variety='REGULAR')

File "C:\Users\cheer\Anaconda3\lib\site-packages\kiteconnect-3.7.6-py3.7.egg\kiteconnect\connect.py", line 326, in place_order
return self._post("order.place", params)["order_id"]

File "C:\Users\cheer\Anaconda3\lib\site-packages\kiteconnect-3.7.6-py3.7.egg\kiteconnect\connect.py", line 701, in _post
return self._request(route, "POST", params)

File "C:\Users\cheer\Anaconda3\lib\site-packages\kiteconnect-3.7.6-py3.7.egg\kiteconnect\connect.py", line 766, in _request
raise exp(data["message"], code=r.status_code)

InputException: Invalid `api_key` or `access_token`
  • rakeshr
    @svprasad
    Initilization of kite should be changed from
    kite=KiteConnect(api_key,api_secret)
    to
    kite = KiteConnect(api_key="your_api_key")
Sign In or Register to comment.