permission issue for API

Tusshar18
Tusshar18 edited August 2021 in Kite Publisher
We would like to inform you that the above error is a permission issue for historical API, request you to write to forum for code related queries.

How to correct this, have also changed the api secret
  • sujith
    Did you create a new session after subscribing for historical data?
  • Tusshar18
    still getting the same error
    Even subscribed for historical API
  • Tusshar18
    TypeError Traceback (most recent call last)
    in
    ----> 1 re_ce_price = candle_close(re_ce_token, entry_time)
    2 re_pe_price = candle_close(re_pe_token, entry_time)
    3 re_ce_sl_price = int(re_ce_price * (1+(sl/100))) + 1
    4 re_pe_sl_price = int(re_pe_price * (1+(sl/100))) + 1
    5

    ~\Desktop\Zerodha\v2\misc_func.py in candle_close(scrip_token, sl_time)
    25 }
    26 x = requests.get(url, headers=headers)
    ---> 27 for i in range(len(x.json()['data']['candles'])):
    28 if x.json()['data']['candles'][i][0][11:16] == sl_time:
    29 candle_minute_close = x.json()['data']['candles'][i][4]

    TypeError: 'NoneType' object is not subscriptable
  • sujith
    This doesn't seem like an API error. Can you paste the complete request and response logs?
    You can run in debug mode and paste the logs here.

    PS: Make sure to remove app and client specific tokens.
  • Tusshar18
    It is an API error only, sent this to zerodha, and got
    "We would like to inform you that the above error is a permission issue for historical API, request you to write to forum for code related queries."
  • rakeshr
    x = requests.get(url, headers=headers)
    candle_minute_close = x.json()['data']['candles'][i][4]
    TypeError: 'NoneType' object is not subscriptable
    You seem to be setting wrong requests for historical data. Can you let us know more about url and headers for requests?
    Also, you can make use of any of our official client libs, which have easy API integration.
  • Tusshar18
    Tusshar18 edited August 2021
    def candle_close(scrip_token, sl_time):
    global cookies, today
    url = 'https://kite.zerodha.com/oms/instruments/historical/'+ str(scrip_token) +'/minute?user_id=' + str(user_id) + '&oi=1&from=' + today + '&to=' + today + '&ciqrandom=1597949155770'
    headers = {
    'authorization': cookies
    }
    x = requests.get(url, headers=headers)
    for i in range(len(x.json()['data']['candles'])):
    if x.json()['data']['candles'][i][0][11:16] == sl_time:
    candle_minute_close = x.json()['data']['candles'][i][4]
    return candle_minute_close


    the above function is the one giving error
  • rakeshr
    Above doesn't seem to be kite connect API request. You need to purchase kite connect API for making API based request.
This discussion has been closed.