我使用的应用程序接口需要MD5加密才能处理POST请求。我尝试使用文档代码向接口发出'userBalance‘请求,但每次它都返回{’https://www.allcoin.ca/api_market/market‘:1,'msg':'签名校验失败'} (这意味着签名检查失败)。接口只需要两个参数,分别是api_key和sign。我仔细地遵循文档的指导,但API仍然拒绝该帖子。有没有关于签名检查失败的建议?我是不是遗漏了什么?
import hashlib
import keys
import requests
KEY = keys.allcoin["key"]
API_SECRET = keys.allcoin["secret"]
msg = "api_key='{}&secret_key={}".format(KEY, API_SECRET)
signature = hashlib.md5(msg.encode("utf-8")).hexdigest()
parameters = {
"api_key": KEY,
"sign": signature.upper(),
}
params = "&".join("{}={}".format(a, b) for a, b in parameters.items())
url = "http://www.allcoin.ca/Api_User/userBalance"
r = requests.post(
headers={
"Content-Type": "application/x-www-form-urlencoded",
'user-agent': 'my-app/0.0.1'
},
url=url,
params=parameters
)
print(r.json())发布于 2018-04-25 05:00:34
我认为您希望在requests.post()中将params=parameters更改为params=params。
https://stackoverflow.com/questions/50010601
复制相似问题