I am getting error in this code as I am unable to read the JSON data properly
import requests
from operator import itemgetter
import json
import webbrowser
url = 'https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?earth_date='
apikey=('DEMO_KEY')
earth_date = input('please enter the required date in yyyy-m-dd format')
URL = (url + earth_date +'&api_key=' + apikey)
print(URL)
r =requests.get(URL)
print('Status code:',r.status_code)
response_dict = json.loads(r.text)
response_dict = r.json()
for rover_data in response_dict:
print('image url:',rover_data['img_src'])
webbrowser.open(rover_data['img_src'])
This the error I am getting
please enter the required date in yyyy-m-dd format2015-6-11
https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?earth_date=2015-6-11&api_key=DEMO_KEY
Status code: 200
Traceback (most recent call last):
File "d:\Python Programs\rover data.py", line 15, in <module>
print('image url:',rover_data['img_src'])
TypeError: string indices must be integers
can anyone please help me?