Python Forum
'int' object is not subscriptable after API call
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
'int' object is not subscriptable after API call
#1
I am getting this error when I try to create a DataFrame from an API call. The API call itself is successful and returns data successfully..but not sure about the error after.
import numpy as np import pandas as pd import requests import json from datetime import datetime import matplotlib.pyplot as plt import http.client
conn = http.client.HTTPSConnection("api.sportradar.us") conn.request("GET", "/nhl/trial/v7/en/seasons/2020/REG/teams/4416091c-0f24-11e2-8525-18a905767e44/analytics.json?api_key={apikey}") res = conn.getresponse() data = res.read() print(data.decode("utf-8"))
placeholder for API key.

df = pd.json_normalize(data, 'id') df.head(10)
   

Error:
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-49-51d43eff599e> in <module> ----> 1 df = pd.json_normalize(data, 'id') 2 df.head(10) ~\anaconda3\envs\Python_DS\lib\site-packages\pandas\io\json\_normalize.py in _json_normalize(data, record_path, meta, meta_prefix, record_prefix, errors, sep, max_level) 339 records.extend(recs) 340 --> 341 _recursive_extract(data, record_path, {}, level=0) 342 343 result = DataFrame(records) ~\anaconda3\envs\Python_DS\lib\site-packages\pandas\io\json\_normalize.py in _recursive_extract(data, path, seen_meta, level) 311 else: 312 for obj in data: --> 313 recs = _pull_records(obj, path[0]) 314 recs = [ 315 nested_to_record(r, sep=sep, max_level=max_level) ~\anaconda3\envs\Python_DS\lib\site-packages\pandas\io\json\_normalize.py in _pull_records(js, spec) 250 if has non iterable value. 251 """ --> 252 result = _pull_field(js, spec) 253 254 # GH 31507 GH 30145, if result is not Iterable, raise TypeError if not ~\anaconda3\envs\Python_DS\lib\site-packages\pandas\io\json\_normalize.py in _pull_field(js, spec) 241 result = result[field] 242 else: --> 243 result = result[spec] 244 return result 245 TypeError: 'int' object is not subscriptable
   

I have tried quite a few different things to create a DF.
Larz60+ write Sep-18-2021, 01:31 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Refrain from using images for code.
Reply
#2
Hello,

Hope the update is good!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting this TypeError: 'TreasureMap' object is not subscriptable. makilakos 2 2,100 May-25-2024, 07:58 PM
Last Post: deanhystad
Bug TypeError: 'NoneType' object is not subscriptable TheLummen 4 5,077 Nov-27-2023, 11:34 AM
Last Post: TheLummen
  Help with python 'not subscriptable' error Extra 3 5,687 Dec-16-2022, 05:55 PM
Last Post: woooee
  TypeError: 'NoneType' object is not subscriptable syafiq14 3 7,683 Sep-19-2022, 02:43 PM
Last Post: Larz60+
  Message='int' object is not subscriptable DanielCook 4 4,250 Aug-10-2021, 05:21 PM
Last Post: deanhystad
  Bool Object is not Subscriptable quest 1 6,113 May-02-2021, 11:12 AM
Last Post: Yoriz
  Float Object is not Subscriptable quest 2 4,617 Apr-20-2021, 09:28 AM
Last Post: quest
  how to call an object in another function in Maya bstout 0 3,220 Apr-05-2021, 07:12 PM
Last Post: bstout
  TypeError: 'NoneType' object is not subscriptable Jmekubo 6 35,257 Sep-08-2020, 10:03 AM
Last Post: DigiTMG
  TypeError: 'type' object is not subscriptable Stef 1 8,138 Aug-28-2020, 03:01 PM
Last Post: Gribouillis

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.