Error in fetching NFO instruments

import pandas as pd
kiteObj = KiteConnect(api_key=api_key)
df = pd.DataFrame(kiteObj.instruments("NFO"))

This works as expected, but i was overlooking server logs one time, and found this error, can you explain what could've caused this error? @sujith

Logs: - - [16/Apr/2022 18:04:28] "GET /instruments HTTP/1.1" 200 209 0.015625
Exception in thread Thread-2:
Traceback (most recent call last):
File "C:\Users\Knight\AppData\Local\Programs\Python\Python38-32\lib\", line 932, in _bootstrap_inner
File "C:\Users\Knight\AppData\Local\Programs\Python\Python38-32\lib\", line 870, in run
self._target(*self._args, **self._kwargs)
File "E:\Users\Knight\Downloads\new-projects\helloworld\", line 430, in instrument_updater
df = pd.DataFrame(kiteObj.instruments("NFO"))
File "E:\Users\Knight\Downloads\new-projects\helloworldvenv\lib\site-packages\kiteconnect\", line 556, in instruments
return self._parse_instruments(self._get("market.instruments", url_args={"exchange": exchange}))
File "E:\Users\Knight\Downloads\new-projects\helloworldvenv\lib\site-packages\kiteconnect\", line 837, in _get
return self._request(route, "GET", url_args=url_args, params=params, is_json=is_json)
File "E:\Users\Knight\Downloads\new-projects\helloworldvenv\lib\site-packages\kiteconnect\", line 919, in _request
raise ex.DataException("Unknown Content-Type ({content_type}) with response: ({content})".format(
kiteconnect.exceptions.DataException: Unknown Content-Type (text/html) with response: (b'<html>\r\n<head><title>502 Bad Gateway</title></head>\r\n<body>\r\n<center><h1>502 Bad Gateway</h1></center>\r\n</body>\r\n</html>\r\n') - - [16/Apr/2022 18:04:30] "POST /update-api-credentials HTTP/1.1" 200 162 0.015666
    Are you fetching instruments file multiple times without delay??

    Instruments dump is a very large file. The instruments api shouldn't be polled continuously.
    It only updates once in the morning every trading day.
    So ,you can just fetch it once/day and store in your database for that trading day.
  • nkotwar
    I only fetch instruments file once during login time each day.
    But this error came when i was debugging something locally, I did fetch this file multiple times during debugging, can that cause 502?
  • nkotwar
    Okay. Thanks.
This discussion has been closed.