Post API授权
问题描述:
我是python的初学者,但我想从我的私人帐户在cryptocurrency市场bitbay.net上获取信息数据。Post API授权
Api description can be found here:
我在Python 3.5的代码:
import requests
import json
import hashlib
import time
hash_object = hashlib.sha512(b'public_api_xxxxxx')
apihash = hash_object.hexdigest()
timestamp = time.time()
p = requests.post('https://bitbay.net/API/Trading/tradingApi.php', data={'API-Key':'public_api_xxxxxx','API-Hash':apihash,'Moment':timestamp, 'Method':'info' })
p.text
print(p)
我花很多时间来解决这个问题,但我仍然得到:
响应[404]
您的援助将非常感谢。为了获得最佳答案,我想购买小啤酒:)提前谢谢!
答
apihash = hmac.new(secret, data, hashlib.sha512).hexdigest()
此外,从文档,API-Key
和API-Hash
是头。 moment
& method
场URL编码在体内
Python2
import requests
import hashlib
import hmac
import time
import urllib
secret = "12345"
apiKey = "public_api_xxxxxx"
timestamp = int(time.time())
data = urllib.urlencode((('method', 'info'),('moment', timestamp)))
apihash = hmac.new(secret, data, hashlib.sha512).hexdigest()
res = requests.post('https://bitbay.net/API/Trading/tradingApi.php',
headers={
'API-Key':apiKey,
'API-Hash' : apihash,
'Content-Type' : 'application/x-www-form-urlencoded'
},
data=data
)
print(res)
print(res.text)
Python3
import requests
import hashlib
import hmac
import time
import urllib
secret = b"12345"
apiKey = "public_api_xxxxxx"
timestamp = int(time.time())
data = urllib.parse.urlencode((('method', 'info'),('moment', timestamp)))
apihash = hmac.new(secret, data.encode('utf-8'), hashlib.sha512).hexdigest()
res = requests.post('https://bitbay.net/API/Trading/tradingApi.php',
headers={
'API-Key':apiKey,
'API-Hash' : apihash,
'Content-Type' : 'application/x-www-form-urlencoded'
},
data=data
)
print(res)
print(res.text)
感谢您的帮助!你是老板:)请给我你的cryptocurrency钱包地址 - 我想给你买一杯啤酒:) – Max
不客气,我很高兴能够帮到你,如果你喜欢它,你可以接受/赞成答案,会很好:) –
好的。谢谢 :) – Max