I’m trying to get the current location of International Space Station(ISS) and display it in a json format.
The code seems okay but I keep getting error and I don’t know why.
import requests
sample = requests.get(url="http://open-notify.org/Open-Notify-API/ISS-Location-Now/")
conv= sample.json()
print(conv)
I was expecting the code to return a json of the current location of the ISS but I kept getting this error instead
Traceback (most recent call last):
File "C:\Users\Guest\PycharmProjects\Api\main.py", line 7, in <module>
conv = sample.json()
^^^^^^^^^^^^^
File "C:\Users\Guest\AppData\Local\Programs\Python\Python312\Lib\site-packages\requests\models.py", line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
>Solution :
You are using the documentation link, not the actual API link;
http://api.open-notify.org/iss-now.json
So the code becomes:
import requests
sample = requests.get(url="http://api.open-notify.org/iss-now.json")
conv= sample.json()
print(conv)
Printing:
{'iss_position': {'longitude': '-97.8479', 'latitude': '16.1262'}, 'message': 'success', 'timestamp': 1701706077}