我是新的python。只需幾個小時的時間來學習消費Blinktrade Rest API與Python給出的錯誤
我試圖消耗的REST API得到一些賬戶的相關信息...
這裏是我的要求:
def getAccountData():
nonce = int(datetime.datetime.now().timestamp())
signature = hmac.new(b'TDDh8djV3NwXt53gSrScDul6o6w3HnnZsHuh6HTF9SA', msg=nonce, digestmod=hashlib.sha256).digest()
print(signature)
headers = {
'content-type': 'application/json',
'APIKey':conf['API_KEY'],
'Nonce':str(nonce),
}
data = {
"MsgType": "U2",
"BalanceReqID": 1
}
r = requests.post('https://api.blinktrade.com/tapi/v1/message', data=data, headers=headers)
print(r.json())
這裏是錯誤:
Traceback (most recent call last): File "foxbit.py", line 51, in getAccountData() File "foxbit.py", line 30, in getAccountData signature = hmac.new(b'TDDh8djV3NwXt53gSrScDul6o6w3HnnZsHuh6HTF9SA', msg=nonce, digestmod=hashlib.sha256).digest() File "C:\Python\Python35\lib\hmac.py", line 144, in new return HMAC(key, msg, digestmod) File "C:\Python\Python35\lib\hmac.py", line 84, in init self.update(msg) File "C:\Python\Python35\lib\hmac.py", line 93, in update self.inner.update(msg) TypeError: object supporting the buffer API required
我試圖消費這個API: https://blinktrade.com/docs/?shell#balance
on balance
方法
沒有成功。
我想創建和python應用程序來觀看我已開立的比特幣訂單。 這個錯誤發生了什麼?關於文件,說我需要這樣做的工作:
{
"MsgType": "U2",
"BalanceReqID": 1
}
message='{ "MsgType": "U2", "BalanceReqID": 1 }'
api_url='API_URL_REST_ENDPOINT'
api_key='YOUR_API_KEY_GENERATED_IN_API_MODULE'
api_secret='YOUR_SECRET_KEY_GENERATED_IN_API_MODULE'
nonce=`date +%s`
signature=`echo -n "$nonce" | openssl dgst -sha256 -hex -hmac "$api_secret" | cut -d ' ' -f 2`
curl -X POST "$api_url" \
-H "APIKey:$api_key" \
-H "Nonce:$nonce" \
-H "Signature:$signature" \
-H "Content-Type:application/json" \
-d "$message"
3小時嘗試它,沒有什麼!呵呵 我需要一些幫助。