I am very new to programming and I am having a problem with the following:
I have a very simple and perhaps pointless task whereby I am trying to take longitude and latitude data from a JSON API and write to a CSV file. I have based the code on another that seems to work OK.
I keep getting the following error code: _
c.writerow([item['latitude']])_TypeError: string indices must be integers
Can anyone help me??
1.JSON API from http://api.open-notify.org/iss-now.json
2.My Python Code
import requests import csv r = requests.get("http://api.open-notify.org/iss-now.json").json() c = csv.writer(open("ISS.csv", "w"),lineterminator='\n') for item in r['iss_position']: c.writerow([item['latitude'],['longitude']])
Traceback (most recent call last):
File "C:/Users/Ian/PycharmProjects/ISS/ISS.py", line 10, in
TypeError: string indices must be integers
Process finished with exit code 1
Replace this line with your code.