0

This is the sample code provided within the api documentation:

#!/bin/bash 
apiKey="yourApiKey"
secret="yourSecret"
curl -i \
-X GET \
-H 'Accept:application/json' \
-H 'Api-key:'$apiKey'' \
-H 'X-Signature:'$(echo -n ${apiKey}${secret}$(date +%s)|sha256sum|awk '{ print $1}')'' \
https://api.test.hotelbeds.com/hotel-api/1.0/status

This is what I am doing in python:

secret = b"Secret key"
apikey = b"Api key"
datenow = str(datetime.datetime.now().timestamp())
datenow = bytes(datenow, 'utf-8')

sig = apikey + secret + datenow

hash = hashlib.sha256(sig).hexdigest()

However, I am getting an authentication error. Can someone please help me fix my code?

2
  • Just use strings instead of bytes? Commented Aug 28, 2020 at 2:31
  • 1
    @BryceWayne I tried that too but it didnt work. Commented Aug 28, 2020 at 2:38

2 Answers 2

1

Problem was solved by converting the date into and int and then into str.

Sign up to request clarification or add additional context in comments.

Comments

0

import hashlib, time

string= str(API_KEY).strip()+str(SECRET).strip()+str(int(time.time())).strip()

signature= hashlib.sha256(string.encode()).hexdigest()

1 Comment

Thank you for this code snippet, which might provide some limited, immediate help. A proper explanation would greatly improve its long-term value by showing why this is a good solution to the problem and would make it more useful to future readers with other, similar questions. Please edit your answer to add some explanation, including the assumptions you’ve made.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.