(Jan-06-2018, 06:16 PM)wavic Wrote: Consider that base64.b64encode(hmac.new(base64.b64decode( API_SECRET ), signature, hashlib.sha256).digest())
will return bytes again. So you have to convert it to string. As before
Thank you very much!
Now you will understand and change code.
(Jan-06-2018, 06:25 PM)Zhsv Wrote:(Jan-06-2018, 06:16 PM)wavic Wrote: Consider thatbase64.b64encode(hmac.new(base64.b64decode( API_SECRET ), signature, hashlib.sha256).digest())
will return bytes again. So you have to convert it to string. As before
Thank you very much!
Now you will understand and change code.
So changed. The error persists
elif method in private_set: url = "https://www.cryptopia.co.nz/Api/" + method nonce = str( int( time.time() ) ) post_data = json.dumps( req ); m = hashlib.md5() m.update(post_data.encode('utf-8')) requestContentBase64String = base64.b64encode(m.digest()).decode('utf-8') signature = API_KEY + "POST" + urllib.parse.quote_plus( url ).lower() + nonce + requestContentBase64String hmacsignature = base64.b64encode(hmac.new(base64.b64decode( API_SECRET ), signature, hashlib.sha256).digest()).decode('utf-8') header_value = "amx " + API_KEY + ":" + hmacsignature + ":" + nonce headers = { 'Authorization': header_value, 'Content-Type':'application/json; charset=utf-8' } r = requests.post( url, data = post_data, headers = headers ) response = r.text
Error:def api_query( method = GetBalance, req = {} ):
Traceback (most recent call last):
File "C:/Cloud/Cripto/3.py", line 53, in <module>
print (api_query("GetBalance"))
File "C:/Cloud/Cripto/3.py", line 35, in api_query
hmacsignature = base64.b64encode(hmac.new(base64.b64decode( API_SECRET ), signature, hashlib.sha256).digest()).decode('utf-8')
File "C:\Users\Сергей\AppData\Local\Programs\Python\Python36-32\lib\base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
>>>