poloniex 403禁止使用python3.5

时间:2017-06-25 14:56:15

标签: python python-3.x api request urllib

我正在尝试创建与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中有一个样本包装器

API doc

如何获得与poloniex的基本身份验证连接?

1 个答案:

答案 0 :(得分:0)

根据the Official Documentation

  

&#39; B&#39; :二进制格式。输出基数为2的数字。

在您的代码中,您提供了密钥和密钥。秘密为public int search(int[] nums, int target) { int l = 0; int r = nums.length-1; while(l<=r){ int mid = (l+r)>>1; if(nums[mid]==target){ return mid; } if(nums[mid]> nums[r]){ if(target > nums[mid] || nums[r]>= target)l = mid+1; else r = mid-1; } else{ if(target <= nums[r] && target > nums[mid]) l = mid+1; else r = mid -1; } } return -1; } ,但必须是binary

所以请替换:

string

通过

APIkey = b'provert-kee'
secret = b'ceecret'
相关问题