Python 正在从coinnest.co.kr获取状态代码102
我正在尝试为加密货币交换编写Python包装Python 正在从coinnest.co.kr获取状态代码102,python,rest,api,Python,Rest,Api,我正在尝试为加密货币交换编写Python包装 #!/usr/bin/python2.7 import hashlib import hmac import time base_url = 'https://api.coinnest.co.kr' class Coinnest(): def __init__(self, key, secret): self.key = key self.secret = secret def get_balance(self): ur
#!/usr/bin/python2.7
import hashlib
import hmac
import time
base_url = 'https://api.coinnest.co.kr'
class Coinnest():
def __init__(self, key, secret):
self.key = key
self.secret = secret
def get_balance(self):
url = base_url + '/api/account/balance'
nonce = str(int(time.time())*1000)
key = hashlib.md5(self.secret).hexdigest()
message = 'key={}&nonce={}'.format(self.key, nonce)
signature = hmac.new(key, message, hashlib.sha256).hexdigest()
payload = {'key': key, 'nonce': nonce, 'signature': signature}
r = requests.post(url, data=payload)
return r.json()
coinnest = Coinnest('','')
print coinnest.get_order_history()
响应:u'status':102,u'msg':u',u'data':u'
根据API响应说明:代码102表示
参数错误。所需参数缺失或格式错误
我相信我已经具备了所有必要的参数
多谢各位 文档很糟糕,但看起来您应该使用
md5(secret)
对邮件进行签名,并将key
设置为您的公钥,这与md5(secret)
不同
我还建议使用有序的dict来强制执行参数顺序。在编写代码之前是否尝试过postman测试您的请求?我下载了postman并尝试通过系统运行我的请求。我不确定我的有效负载是否属于授权、标题或正文选项卡。O.Auth 1.0与access token、token secret key最为相似,但md5哈希不是标准函数。[offtopic]但我有很多问题要问coinnest.co.kr的家伙。为什么要使用一些模糊的哈希算法?为什么要使用模糊的错误代码而不是HTTP错误代码?我感觉到了你的痛苦
from collections import OrderedDict
key = self.key
secret_md5 = hashlib.md5(self.secret).hexdigest()
signature = hmac.new(secret_md5, message, hashlib.sha256).hexdigest()
payload = OrderedDict([('key', key), ('nonce', nonce), ('signature', signature)])