WC1 API - Python GET requests returning code 401

Hi all,

I'm trying to use WC1 API with Python requests, but I'm facing issue to get the authorization. Below you can see the code I'm using:

import hmac, hashlib, base64, requests as r
from datetime import datetime

dt = datetime.utcnow().strftime("%a, %d %b %Y %H:%M:%S GMT") # Wed, 14 Dec 2022 23:54:18 GMT

app_key = "******"
app_secret = "****************"

gateway_host = 'api-worldcheck.refinitiv.com'
gateway_url = '/v2/'
scope = 'groups'

dataToSign = f"(request-target): get {gateway_url}{scope}\n host: {gateway_host}\n date: {dt}"
print(dataToSign,'\n')

digest = hmac.new(bytes(app_secret , 'UTF-8'), msg = bytes(dataToSign , 'UTF-8'), digestmod = hashlib.sha256).digest()
signature = base64.b64encode(digest).decode()

authorization = f'Signature keyId="{app_key}",algorithm="hmac-sha256",headers="(request-target) host date",signature="{signature}"'
print(authorization,'\n')

header = { "Date": dt, "Authorization": authorization,}


res = r.get(f'https://{gateway_host}{gateway_url}{scope}', headers=header)

print(res.url, res.status_code)

However I'm always getting the error code 401.

Would you have an example to how to get such authorization using python?

WC1 API - Python requests - Code 401.png

Best Answer

Answers