我正在尝试编写python身份验证机器人:https://comkort.com/page/private_api
没有完整的PHP示例.我猜有人可以把它放在这里.
只有片段的PHP代码:
$query_string = http_build_query($_POST, '', '&');
$ethalon_sign = hash_hmac("sha512", $query_string, $api_secret_key);
Run Code Online (Sandbox Code Playgroud)
如何使用hash_hmac sha512在python上编写身份验证?
我想提取我的open orders POST https://api.comkort.com/v1/private/order/list.
我目前的变种是:
import hashlib
import hmac
import requests
import time
privateKey = b'myprivatekey'
publicKey = 'my public key'
url = 'https://api.comkort.com/v1/private/order/list'
tosign = b'market_alias=doge_ltc'
signing = hmac.new( privateKey , tosign, hashlib.sha512 )
headers = {'sign': signing.digest(), "apikey": publicKey, "nonce": int( time.time() ) }
r = requests.get(url, headers=headers)
print r.text
Run Code Online (Sandbox Code Playgroud)
我抓住了这个
{"code":401,"error":"Invalid sign","field":"sign"}
Run Code Online (Sandbox Code Playgroud)
可能是hexdigest()而不是digest()?我不知道,我正在玩这个b前缀和不同的输出hmac的选项,每次我遇到一个错误:"无效的标志".
我的班级包含三个大词,一个出现在self.__dict__另外两个不是.
例:
class MyClass:
big_matrix = {}
side_array = {}
map_of_data = {}
def __init__( self ):
# etc...
Run Code Online (Sandbox Code Playgroud)
当我试图转储self.__dict__到终端时,我成功地只看到了big_matrixnopt和其他的dicts.
没有一个数组声明__init__,稍后在其他函数中声明.
请帮帮我?