kiteconnect.exception.DataException

SNRaj
Hi I am facing the below error intermittently. Please help me resolve it.
kiteconnect.exception.DataException: Unknown-Content -Type (text/html) with response: BAD Gateway Error
  • rakeshr
    data=kite.instrument('NFO')
    Are you trying to download complete instrument list, too frequently?
    Complete instrument list is a memory heavy file, it should be downloaded once at a day start at your end in DB or to excel, etc file and same should be used further instead of making multiple requests to instrument file.
  • SNRaj
    SNRaj edited June 2021
    Hi Rakeshr thanks for your reply. I am only accessing few instruments(Options) based on the strike price. If you need i can share my entire code for your analysis. Also this error is intermittent.
  • sujith
    @SNRaj,
    It is a huge data dump, you need to download this data once a day and use that as the source.
  • sujith
    You shouldn't be fetching that every now and then.
  • SNRaj
    Thanks Sujith. Can you please let me know how can i filter Banknifty alone from this dump instead of fetching entire NFO data. I am using this piece of code to get the latest weekly expiry date.

    def weekly_expiry():
    data = kite.instruments('NFO')
    x = []
    for i in range(len(data)):
    x.append(data[i]['expiry'])

    x = list(set(x))
    x.sort()

    if datetime.now().month <= x[0].month:
    expiry_date = x[0]

    if x[0].month == x[1].month:
    if x[0].month < 10:
    expiry_date_month = str(x[0].month)
    return x[0].strftime('%y') + x[0].strftime('%#m') + x[0].strftime('%d')
    else:
    expiry_date_month = ((datetime.strptime(str(expiry_date.month), "%m")).strftime("%b"))[0]
    stringDate = str(expiry_date).split('-')
    formatedDate = f"{stringDate[0][2:]}{expiry_date_month.upper()}{stringDate[2]}"

    if x[0].month != x[1].month:
    expiry_date_month = ((datetime.strptime(str(expiry_date.month), "%m")).strftime("%b"))
    stringDate = str(expiry_date).split('-')
    formatedDate = f"{stringDate[0][2:]}{expiry_date_month.upper()}"

    return formatedDate
Sign In or Register to comment.