【发布时间】:2020-12-16 23:08:08
【问题描述】:
这是 api 文档中提供的示例代码:
#!/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
这就是我在 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()
但是,我遇到了身份验证错误。有人可以帮我修复我的代码吗?
【问题讨论】:
-
只使用字符串而不是字节?
-
@BryceWayne 我也试过了,但没用。
标签: python api digital-signature sha256