For a deeper look into our World Check One API, look into:

Overview |  Quickstart |  Documentation |  Downloads

question

Upvotes
Accepted
1 1 0 0

Python Project gives 401 Error when using GetTopLevelGroupRequest. Require Python sample code to generate hmac or signature header. Python signature and Postman signature doesn't match.

Hi,

I have been trying to create a sample API integration project using Python. I have tried to follow the steps as in Postman and as in the Java Sample World Check Application from the Downloads section.

When I run the code, I keep getting the 401 Unauthenticated Error. I believe it is due to the incorrect generation of the hmac. When trying with the same date variable in Postman and Python, the signatures don't match.

Could you please provide a sample code which would help me generate the proper signature so that I can get a groupId as the response? (The response is 200 when doing the same from POSTMAN)

P.S. I have tried using one of the sample code for provided for Python from one of the solutions posted here. That does not seem to work. I tried different methods for generating a similar hmac as CryptoJS does, but it did not work out for me.

Thanks,
Aman

pythonworld-checkworld-check-oneauthentication
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
Accepted
4.5k 4 8 8

@asaraff2,

Thanks for the details.

The issue appears to be with the hmac value which is being generated. Can you please share the dataToSign format which you are using in your code?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
4.5k 4 8 8

@asaraff2,

Can you please share the request and the response headers which you are receiving from your code?

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1 1 0 0

Request Headers:

{'User-Agent': 'python-requests/2.24.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'Authorization': 'Signature keyId="8908a09e-5118-4087-8413-25e20c3867b3",algorithm="hmac-sha256",headers="(request-target) host date",signature="rGGF4v6LRG5h6Cucl7cgzEYpW4OC97xwYueDP3KjYtk="', 'Date': 'Mon, 21 Sep 2020 01:25:40 GMT'}


Response Headers:


{'Strict-Transport-Security': 'max-age=15552000, includeSubdomains', 'Authorization': 'WWW-Authenticate: Signature realm="World-Check One API",algorithm="hmac-sha256",headers="(request-target) host date content-type content-length"', 'Date': 'Mon, 21 Sep 2020 01:25:41 GMT', 'Server': '""', 'Content-Length': '0', 'Age': '430', 'Via': 'HTTPS/1.1 BFAMPHKGWCG01'}

icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1 1 0 0
datatosign = "(request-target): get " + gatewayurl + "groups\n" + \
             "host: " + gatewayhost + "\n" + \
             "date: " + date + "\n"




icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Upvotes
1 1 0 0
gatewayurl = "/v1/"
gatewayhost = "rms-world-check-one-api-pilot.thomsonreuters.com"
dataformat = ("%a, %d %b %Y %H:%M:%S GMT")
datenow = time.gmtime()
date = time.strftime(dataformat, datenow)


icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@asaraff2,

I have dropped you an email so we may investigate further on this.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.