请求标头中的api hmac签名不起作用

时间:2018-02-13 20:16:58

标签: python-2.7 python-requests hmac

我尝试使用ICOBench API访问ICO数据。根据他们的documentation,有必要使用hmac sha384将每个请求与json参数一起签名。

当我不使用任何参数时,签名的工作原理是我只扫描私钥。但是当我尝试使用密钥散列参数时,我得到invalid signature error

部分有效的代码。从api端点返回没有参数的数据:

headers = {'Accept': 'application/json',
           'Content-Type': 'application/json',
           'X-ICObench-Key': PUB_KEY
           }

sig = hmac.new(PR_KEY,digestmod=hashlib.sha384).digest()

headers.update({'X-ICObench-Sig': base64.b64encode(sig)}

response = requests.request('POST', 'https://icobench.com/api/v1/icos/all', headers=headers)

如果我尝试在网址末尾使用参数:

params = {'page':3}

response = requests.request('POST', 'https://icobench.com/api/v1/icos/all', headers=headers, params=params)

返回第0页,就像我们没有使用任何参数一样。

根本不起作用的代码。 invalid signature error。在这里,我使用PR_KEY来散列json数据,与this ICObench js example中的方式相同:

headers = {'Accept': 'application/json',
           'Content-Type': 'application/json',
           'X-ICObench-Key': PUB_KEY
           }

params = {'page':3}

sig = hmac.new(PR_KEY, json.dumps(params), digestmod=hashlib.sha384).digest()

headers.update({'X-ICObench-Sig': base64.b64encode(sig)}

response = requests.request('POST', 'https://icobench.com/api/v1/icos/all', headers=headers)

我错过了什么?

0 个答案:

没有答案