Home > Net >  How to solve "'int' object is not subscriptable" in Django from a Kraken API
How to solve "'int' object is not subscriptable" in Django from a Kraken API

Time:03-02

I was wondering what the correct way is to save a number in Django SQLite coming from a Kraken API, when there is an Array of Array of strings or integers (enter image description here

The SQLite response is actually saving the API number in the database: enter image description here

I researched and tried thoroughly many similar cases here, but none had the example of an API response with this error message.

CodePudding user response:

I think the issue is the with the last item in the "result" array of arrays - "last". It seems like it's just a number. I guess you need some type checking in the algorithm. enter image description here

Suggestion for code modification:

for i in data['result'].values():
  # Skips "last" attribute
  if isinstance(i, int):
    continue
  kraken_data = Krak(
    time_0=(i[0][0]),
  )
  kraken_data.save()
  • Related