apikey = '$mykey'
apisecret = '$mykeysecret'
nonce = str(int(time.time() * 1000))
uri = 'https://somewebsite.com/api/v1.5/account/getbalances?apikey='+apikey+'&nonce='+nonce
sign = hmac.new(b'apisecret', b'uri', hashlib.sha512)
response = requests.get(uri, headers={'apisign': sign}, timeout=10)
print(json.dumps(response, sort_keys=True, indent=4))
""" The following are the example provided by the website """
# $ch = curl_init($uri);
# curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
# $execResult = curl_exec($ch);
# $obj = json_decode($execResult);
# url = "https://somewebsite.com/api/v1.5/account/getbalances?apikey=API_KEY"
经过两个小时的研究,我无法解决这个问题。现在它说头必须是str。但是使用str{'apisign':sign}它说str对象没有项
您正在将字典正确地传递到headers参数中,但错误是
sign
的值不是字符串sign
是HMAC对象,需要转换为字符串:我将查看调用
sign.digest()
以查看它是否返回您期望的字符串。如果是,则可以用headers={'apisign': sign.digest()}
替换headers={'apisign': sign}
相关问题 更多 >
编程相关推荐