I am using Python to get data from the Amadeus API. When I try to call response.json()
on the request, it raises this error:
Traceback (most recent call last):
File "C:UsersjoekiOneDriveDocumentsPython ProjectsCourseDay 30ExercisesPhonetic Alphabet3.8 Python Interpreterlibsite-packagesrequestsmodels.py", line 974, in json
return complexjson.loads(self.text, **kwargs)
File "C:Program FilesPython38libjson__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:Program FilesPython38libjsondecoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:Program FilesPython38libjsondecoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:UsersjoekiOneDriveDocumentsPython ProjectsCourseDay 39Project.py", line 11, in <module>
print(response.json())
File "C:UsersjoekiOneDriveDocumentsPython ProjectsCourseDay 30ExercisesPhonetic Alphabet3.8 Python Interpreterlibsite-packagesrequestsmodels.py", line 978, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
This is my code:
import requests
import datetime
response = requests.get(url="https://developers.amadeus.com/shopping/flight-offers", params={
"originLocationCode": "NYC",
"destinationLocationCode": "LON",
"departureDate": datetime.datetime.now().strftime("%Y-%m-%d"),
"adults": 1
})
response.raise_for_status()
print(response.json())
I don’t know why this error occured when I try to get the JSON data from the response. I wasn’t able to find anything in the documentation that would help me. Is it because my parameter names were incorrect?