Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python requests.json keeps giving errors

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading