Incorrect `api_key` or `access_token`.

Sajansam
I am first time user. Unable to place order. Tried all corrections mentioned in earlier forums
Please suppot

from kiteconnect import KiteConnect
...:
...:
...: In [5]: api_key="my api key from app"
...:
...: In [6]: api_secret="my secret key from app"
...:
...: In [7]: kite=KiteConnect(api_key ="my api key from app")
...:
...: In [8]: kite.login_url()
...:
c:\users\sachin\appdata\local\programs\python\python37-32\lib\site-packages\OpenSSL\_util.py:6: UserWarning: You are using cryptography on a 32-bit Python on a 64-bit Windows Operating System. Cryptography will be significantly faster if you switch to using a 64-bit Python.
from cryptography.hazmat.bindings.openssl.binding import Binding
Out[1]: 'https://kite.zerodha.com/connect/login?api_key=............=3'

In [2]: ...: kite = KiteConnect(api_key="my api key from app")
...: ...:
...: ...: # Set the access token
...: ...: kite.set_access_token("access token received")
...: ...:
...: ...: # Place an order
...: ...: order_id = kite.place_order(
...: ...: tradingsymbol="SBIN",
...: ...: quantity=1,
...: ...: exchange="NSE",
...: ...: order_type="MARKET",
...: ...: transaction_type="BUY",
...: ...: product="CNC",
...: ...: variety="regular")
...: ...:
...: ...: print("Order placed. ID is:", order_id)
---------------------------------------------------------------------------
TokenException Traceback (most recent call last)
in
12 transaction_type="BUY",
13 product="CNC",
---> 14 variety="regular")
15
16 print("Order placed. ID is:", order_id)

c:\users\sachin\appdata\local\programs\python\python37-32\lib\site-packages\kiteconnect\connect.py in place_order(self, variety, exchange, tradingsymbol, transaction_type, quantity, product, order_type, price, validity, validity_ttl, disclosed_quantity, trigger_price, iceberg_legs, iceberg_quantity, auction_number, tag)
361 return self._post("order.place",
362 url_args={"variety": variety},
--> 363 params=params)["order_id"]
364
365 def modify_order(self,

c:\users\sachin\appdata\local\programs\python\python37-32\lib\site-packages\kiteconnect\connect.py in _post(self, route, url_args, params, is_json, query_params)
863 def _post(self, route, url_args=None, params=None, is_json=False, query_params=None):
864 """Alias for sending a POST request."""
--> 865 return self._request(route, "POST", url_args=url_args, params=params, is_json=is_json, query_params=query_params)
866
867 def _put(self, route, url_args=None, params=None, is_json=False, query_params=None):

c:\users\sachin\appdata\local\programs\python\python37-32\lib\site-packages\kiteconnect\connect.py in _request(self, route, method, url_args, params, is_json, query_params)
935 # native Kite errors
936 exp = getattr(ex, data.get("error_type"), ex.GeneralException)
--> 937 raise exp(data["message"], code=r.status_code)
938
939 return data["data"]

TokenException: Incorrect `api_key` or `access_token`.
  • sujith
    It usually means you are sending an invalid api_key or access_token. You can enable debug logs of pykiteconnect and inspect request and response json.
Sign In or Register to comment.