尽管有许多关于Poloniex / Python交易api访问的帖子,但我仍然不知道如何在Python3.6上实现这一点。这里有一个版本,在我看来,它应该是完美的,但不是:
req['command'] = 'requestBalances'
req['nonce'] = int(time.time() * 1000)
post_data = urllib.parse.urlencode(req).encode('utf-8')
hmac_key = self.Secret.encode('utf-8')
sign = hmac.new(hmac_key, post_data, hashlib.sha512)
sign = sign.hexdigest()
headers = {
'Sign': sign,
'Key': self.APIKey
}
res = requests.post('https://poloniex.com/tradingApi', data=post_data, headers=headers)如果我使用正确的api /密码运行上面的代码,我会得到一个"invalid command“错误。
有趣的是,如果我将requests.post函数替换为:
req = urllib.request.Request(url='https://poloniex.com/tradingApi', data=post_data, headers=headers)
res = urllib.request.urlopen(req,timeout=5)然后我没有得到一个错误,而是一个空的字节数组(在res.read()之后)
任何关于如何使这项工作的提示将非常感谢。
发布于 2017-05-31 21:14:36
解决方案包括:
"Content-type": "application/x-www-form-urlencoded"在报头中,即:
headers = {
"Content-type": "application/x-www-form-urlencoded",
'Sign': sign,
'Key': self.APIKey
}奇怪的是,我见过的其他解决方案都没有包括这个额外的字段,但我们就这样做了。
PS。另一种使用urllib.request的方法仍然只返回一个空字节串。
https://stackoverflow.com/questions/44285353
复制相似问题