When I tried to return a date in my python api request, I get the error message 'Object of type date is not JSON serializable'. I converted it to JSON using this function below:
def myconverter(o):
if isinstance(o, datetime.datetime):
return o.__str__()
Now it is returning a null value and also the error message .
'JSONDecodeError at /search/ Expecting value: line 1 column 1 (char 0)'
What am i doing wrongly?This is my code below:
new_parameter=json.dumps(parameters, default = myconverter)
print(new_parameter)
urls = 'https://ije-api.tcore.xyz/v1/flight/search-flight'
result = requests.post(urls,json=new_parameter,headers=headers).json()
print(result.text)
flight ={
"departure_date": result['body']['data']['itineraries'][0]['origin_destinations'][0]['segments'][0]['departure']['date'],
"departure_time": result['body']['data']['itineraries'][0]['origin_destinations'][0]['segments'][0]['departure']['time'],
}
print(result)