mirror of
https://github.com/FranP-code/countries.git
synced 2025-10-13 00:02:15 +00:00
Update PythonExampleUsage.py
`requests.post` takes a `json` parameter that will convert to json and the header
This commit is contained in:
@@ -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") {
|
country(code: "BR") {
|
||||||
name
|
name
|
||||||
@@ -16,18 +15,7 @@ query = """
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"""
|
'''}
|
||||||
|
|
||||||
|
r = requests.post(url, json=json)
|
||||||
def get_country_data(arguments='{}'):
|
print(r.json())
|
||||||
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))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user