KiteConnect while fetching historic data is giving error

vpkartha
While I am trying to get historic data with the below code: it is giving error . The error is also appended below
records = kite.historical_data(token,from_date =from_dt,to_date = to_dt,interval=interval)

Error: kiteconnect.exceptions.InputException: Invalid `api_key` or `access_token`.

I have checked and my api_key is correct and historic data dont need access token as a parameter. What could be the reason. My I have subscribed to Historic data as an add-on
  • ganeshv02
    @vpkartha - looks like token issue. Are you able to a simple query of your holdings?

    kite.holdings()
  • vpkartha
    token: {55875591:"CRUDEOIL20AUGFUT"} and I am getting value as 55875591. Then why.?

    I tried tp get the margin. Same error
  • sujith
    @vpkartha,
    Did you generate a new access token after subscribing to historical data API?
  • vpkartha
    Yes. I have generated the new access token today morning'
  • vpkartha
    vpkartha edited August 2020
    Access to token generating code:

    C:\Users\DELL\Desktop\Python Files>py getaccesstoken.py
    Generate Access Token : https://kite.trade/connect/login?api_key=58w567phg1riwrq5&v=3
    [+])Enter your request token here :bmmKd7ysC2mjXa6NVxtKqqvKR023WFqMN4
    R0liGCeuKy505B1GSta135ePHcPrR4i

  • sujith
    Make sure you never post app or client-specific details on the public thread. You can post it as a private message if you have to do so.
  • sujith
    Can you run pykiteconnect in debug mode and paste the complete stacktrace here? Make sure to remove the app-specific tokens.
  • vpkartha
    But I dont know how to do it. Please advise
  • rakeshr
    But I dont know how to do it. Please advise
    You need to add python logging info in your requests. Check an example here.
  • vpkartha
    DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.kite.trade:443
    DEBUG:urllib3.connectionpool:https://api.kite.trade:443 "POST /orders/regular HTTP/1.1" 400 109
    Traceback (most recent call last):
    File "C:\Users\DELL\Desktop\Python Files\import logging.py", line 18, in
    order_id = kite.place_order(tradingsymbol="INFY",
    File "C:\Users\DELL\AppData\Roaming\Python\Python38\site-packages\kiteconnect\connect.py", line 346, in place_order
    return self._post("order.place", params)["order_id"]
    File "C:\Users\DELL\AppData\Roaming\Python\Python38\site-packages\kiteconnect\connect.py", line 821, in _post
    return self._request(route, "POST", params)
    File "C:\Users\DELL\AppData\Roaming\Python\Python38\site-packages\kiteconnect\connect.py", line 886, in _request
    raise exp(data["message"], code=r.status_code)
    kiteconnect.exceptions.InputException: Invalid `api_key` or `access_token`.

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "C:\Users\DELL\Desktop\Python Files\import logging.py", line 28, in
    logging.info("Order placement failed: {}".format(e.message))
    AttributeError: 'InputException' object has no attribute 'message'
    [Finished in 1.3s]
  • sujith
    You may try and print the api_key and access token before making the request. It seems like the auth header doesn't have either of the tokens.
  • vpkartha
    I have done that and it is result is correct
  • vpkartha
    Api Key: xxxxxxxxxxxxxxx
    api_secret : xxxxxxxxxxxxxxxxxxxxx
    access_token : xxxxxxxxxxxxxxxxxx

    I have masked the actual keys
  • sujith
    This is for order place, you may be sending a wrong variety param.
  • sujith
    Variety is a lower case value like regular, bo, co, amo
  • sujith
    Like I have mentioned above, you seem to be accessing the wrong route because of the wrong variety param while placing order.
  • vpkartha
    hello I have entered in lower case

  • vpkartha
    Hi Sujit, shall I send you the entire code for my historical data extraction to your personal mail. Can you help me.. My phone / whatsapp number is 7606057921
  • vpkartha
    I am not able to get my margins also. That also is extracted through kite connect. There also, I m getting the same error . api_key invalid
  • vpkartha
    hello Sujit, Any reply..?
  • sujith
    @vpkartha,
    We don't provide support for writing code. The pykiteconnect is a stable library that is being used in production on many of our platforms and third-party users as well.
    We don't see any issue from our end.
    According to the above debug logs, the issue seems to be happening from place order, and in the above code product value being sent is wrong.
    Your debug logs and the error description doesn't match. You need to debug code at your end.
Sign In or Register to comment.