import hashlib import hmac import base64 import urllib from datetime import datetime import requests as r # use for fiddler debugging #import os print("Start") # set fiddler proxy #os.environ['HTTP_PROXY'] = 'http://127.0.0.1:8888' #os.environ['http_proxy'] = 'http://127.0.0.1:8888' #os.environ['HTTPS_PROXY'] = 'http://127.0.0.1:8888' #os.environ['https_proxy'] = 'http://127.0.0.1:8888' ########## API Protocol, Domain, and Path ########## protocol = 'https://' domain = 'content1-api.1worldsync.com' path = 'V1/product/fetch' ########## Query Parameters ########## # Required Parameters # app_id = 'your_appid' #client id secretKey = 'your_secret_key' #client secret page_size = '1' time_stamp = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ') string_to_hash = "/{}?timestamp={}&pageSize={}".format(path, time_stamp, page_size) # Hashing Custom String # message = bytes(string_to_hash, 'utf-8') #data bytes secret = bytes(secretKey, 'utf-8') #key bytes hash = hmac.new(secret, message, hashlib.sha256) # Retrieving Hash Code # hash_code = base64.b64encode(hash.digest()) urlencoded_hash = urllib.parse.quote(hash_code).replace('/','%2F') requestURL= "{}{}/{}?timestamp={}&pageSize={}".format(protocol, domain, path , urllib.parse.quote(time_stamp), page_size) #Body payload = { } headers = { "appId" : app_id, "hashcode" : hash_code } # Making the GET Request # response = r.post(requestURL, headers=headers, json=payload) print(requestURL) print(response) print(response.status_code) print(response.text) print("End")