From 4f430e40409bf37091bf5f63f2e0c56b69624586 Mon Sep 17 00:00:00 2001 From: Gabriel Sroka Date: Tue, 23 Nov 2021 08:05:43 -0800 Subject: [PATCH] Update PythonExampleUsage.py `requests.post` takes a `json` parameter that will convert to json and the header --- examples/python/PythonExampleUsage.py | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/examples/python/PythonExampleUsage.py b/examples/python/PythonExampleUsage.py index b8fef41..223e44b 100644 --- a/examples/python/PythonExampleUsage.py +++ b/examples/python/PythonExampleUsage.py @@ -1,9 +1,8 @@ -import requests, json +import requests -FETCH_COUNT = 50 -URL = "https://countries.trevorblades.com" +url = "https://countries.trevorblades.com" -query = """ +json = {'query': ''' { country(code: "BR") { name @@ -16,18 +15,7 @@ query = """ } } } -""" +'''} - -def get_country_data(arguments='{}'): - arguments = dict(query=arguments) # wrap query in dictionary - - graph_ql_request = requests.post(URL, - data=json.dumps(arguments), - headers={"Content-type": "application/json"}) - - country_data = graph_ql_request.json() - return country_data - - -print(get_country_data(arguments=query)) +r = requests.post(url, json=json) +print(r.json())