-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathsample.py
37 lines (26 loc) · 859 Bytes
/
sample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import requests
token_endpoint = 'https://icdaccessmanagement.who.int/connect/token'
client_id = '...'
client_secret = '...'
scope = 'icdapi_access'
grant_type = 'client_credentials'
# get the OAUTH2 token
# set data to post
payload = {'client_id': client_id,
'client_secret': client_secret,
'scope': scope,
'grant_type': grant_type}
# make request
r = requests.post(token_endpoint, data=payload, verify=False).json()
token = r['access_token']
# access ICD API
uri = 'https://id.who.int/icd/entity'
# HTTP header fields to set
headers = {'Authorization': 'Bearer '+token,
'Accept': 'application/json',
'Accept-Language': 'en',
'API-Version': 'v2'}
# make request
r = requests.get(uri, headers=headers, verify=False)
# print the result
print (r.text)