Key Error while assigning historical data to a variable

while fetching historical candle data and assigning it to a variable

hist_data = fyers.history(data)

df = pd.DataFrame(hist_data[“candles”], columns=[‘date’,‘open’,‘high’,‘low’,‘close’,‘volume’])

is giving keyError: ‘candles’

Can someone help me to resolve this… I am new to coding.. Thanks

Hey Soma,
Next time print just the hist_data variable before the next line,
In the error above I feel the candles keyword is not coming in the dictionary.

So you can have a condition like this,
if hist_data[“candles”]:
df = pd.DataFrame(hist_data[“candles”], columns=[‘date’,‘open’,‘high’,‘low’,‘close’,‘volume’])