Parsing a strava .json file and "TypeError: 'NoneType' object is not subscriptable" suddenly appeared when running a python script"

Viewed 18

I have been using a series of (almost) identical python scripts to parse my strava activities.json file, amongst other things, to extract & display a map of the exercise track. After doing an apt update & apt upgrade (ubuntu system), I now have the error-

"TypeError: 'NoneType' object is not subscriptable"
Traceback (most recent call last):
  File "/var/lib/strava/./latlong1.py", line 42, in <module>
    summary_polyline = dict_item["map"]["summary_polyline"]
TypeError: 'NoneType' object is not subscriptable

appearing on running all 5 scripts. Up until the update, these scripts have worked perfectly for almost 2 years. Below is one of the scripts, and the error it produces. I have read a number of "explanations" of the error, but all merely repeat the wording of the error- which I already don't understand. Thanks for any assistance.

First the relevant code-

# json_contents is a List with dicts now
json_contents = json.loads(contents)
# list of summary_polyline
summary_polyline_list = []
for dict_item in json_contents:
   #extract summary_polyline from dict map
    summary_polyline = dict_item["map"]["summary_polyline"]
    #activities.append(summary_polyline)
    summary_polyline_list.append(summary_polyline)
name_list = []


name_list = []
for dict_item in json_contents:
#   extract names from dict
    name = dict_item["name"]
#   activities.append(name)
    name_list.append(name)
# list of summary_polyline
    summary_polyline_list = []
    for dict_item in json_contents:
#extract summary_polyline from dict map
       summary_polyline = dict_item["map"]["summary_polyline"]
#activities.append(summary_polyline)
       summary_polyline_list.append(summary_polyline)

And the error it now produces-

Traceback (most recent call last):
  File "/var/lib/strava/./latlong1.py", line 42, in <module>
    summary_polyline = dict_item["map"]["summary_polyline"]
TypeError: 'NoneType' object is not subscriptable
0 Answers
Related