Dopo la versione in Go la medesima funzione in Python
import requests
from requests.structures import CaseInsensitiveDict
import json
url = "http://xxxxxxxxxxxxx/api/v1/authentication/"
headers = CaseInsensitiveDict()
headers["api-key"] = "apikey"
headers["Accept"] = "application/json"
headers["api-version"] = "v1"
headers["device-language"] = "it"
headers["id-user-session"] = "guest"
headers["Authorization"] = "Basic Z2xxxxxxxxxxxxxxxxxxxxxxxxxxx=="
resp = requests.get(url, headers=headers)
print(resp.content)
if(resp.ok):
jData = json.loads(resp.content)
print("The response contains {0} properties".format(len(jData)))
print("\n")
for key in jData:
print(str(key) + " : " + str(jData[key]))
else:
resp.raise_for_status()
Nessun commento:
Posta un commento