poloniex 403禁止使用python3.5
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了poloniex 403禁止使用python3.5相关的知识,希望对你有一定的参考价值。
我正在尝试创建与poloniex的基本身份验证连接,并且我不断从其API返回403 forbidden错误。
time import time
import urllib.request
import urllib.parse
import hashlib
import hmac
APIkey = b'provert-kee'
secret = b'ceecret'
url = 'https://poloniex.com/tradingApi'
payload = {
'command': 'returnBalances',
'nonce': int(time() * 1000),
}
paybytes = urllib.parse.urlencode(payload).encode('utf8')
print(paybytes)
sign = hmac.new(secret, paybytes, hashlib.sha512).hexdigest()
print(sign)
headers = {
'Key': APIkey,
'Sign': sign,
}
req = urllib.request.Request(url, headers=headers, data=paybytes)
with urllib.request.urlopen(req) as response:
the_page = response.read()
print(the_page)
输出:
#python3 apicalltest3.py
b'command=returnBalances&nonce=1498380606389'
5555555
Traceback (most recent call last):
File "apicalltest3.py", line 29, in <module>
with urllib.request.urlopen(req) as response:
File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.5/urllib/request.py", line 472, in open
response = meth(req, response)
File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.5/urllib/request.py", line 510, in error
return self._call_chain(*args)
File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden
在他们的支持页面上,他们使用hmac 512在python2.7中有一个样本包装器
如何获得与poloniex的基本身份验证连接?
答案
'b':二进制格式。输出基数2中的数字。
在你的代码中,你提供密钥和秘密作为binary
,但它必须是一个string
所以请更换:
APIkey = b'provert-kee'
secret = b'ceecret'
通过
APIkey = 'provert-kee' # or s'provert-kee'
secret = 'ceecret' # or s'ceecret'
以上是关于poloniex 403禁止使用python3.5的主要内容,如果未能解决你的问题,请参考以下文章
windows server 2003 iis配置 出现 http 403 禁止访问,怎么办,网页内显示“你无权查看该网页”