1

帮我登录api poloniex。下面是我尝试登录的代码,但它给了我一个错误!Python 3.5 版。帮助我,请理解我做错了什么!

import urllib
import requests
import json
import time
import hmac,hashlib

api_secret ="111111111111111111111111111111111111111111111111111111111"
api_key="YYYYYYYY-IIIIIIII-PPPPPPPP-LLLLLLLL"

nonce = int(time.time() * 1000)
parms = {"nonce": nonce,"command":'returnBalances'}
post_data = urllib.parse.urlencode(parms)

sign = hmac.new( api_secret.encode(),post_data.encode(), hashlib.sha512).hexdigest()
print(sign)
headers = {"Sign":sign,"Key":api_key}
public = requests.post('https://poloniex.com/tradingApi',post_data,headers)

print(public.text)

程序的结果如下: {"error":"Invalid API key/secret pair."}

4

1 回答 1

0

尝试这个:

import urllib
import urllib2
import requests
import json
import time
import hmac,hashlib

api_secret ="111111111111111111111111111111111111111111111111111111111"
api_key="YYYYYYYY-IIIIIIII-PPPPPPPP-LLLLLLLL"

nonce = int(time.time() * 1000)
parms = {"nonce": nonce,"command":'returnBalances'}
post_data = urllib.parse.urlencode(parms)

sign = hmac.new( api_secret,post_data, hashlib.sha512).hexdigest()
print(sign)
headers = {"Sign":sign,"Key":api_key}
ret = urllib2.urlopen(urllib2.Request('https://poloniex.com/tradingApi', post_data, headers))
jsonRet = json.loads(ret.read())

print(jsonRet)
于 2018-03-22T14:34:24.957 回答