I’m using the following method to insert a variable into a POST request body :
def get_variables(date): return '{{"date":"{0}","timezone":"Europe"}}'.format(date)
The query is the following :
query Exchange($date: String!, $timezone: String) { getIntervals(date: $date, timezone: $timezone) { date intervals { start end description type code } } }
I get this error message when executing get_variable
variables in a POST body should be provided as an object, not a recursively JSON-encoded string.
Any idea for how turn it into a JSON object in python please ?
2
Answers
Update : Resolved.
I've used
json.loads()
function to do the deserialization – the act of converting a string to an object. -->def get_variables(date): return json.loads('{{"date": "{0}", "timezone": "Europe"}}'.format(date))
Thank you all.
Don’t encode this data as a string, return a regular dictionary instead: