3
3
35000sobak2021-05-15 19:06:28
Python
35000sobak, 2021-05-15 19:06:28

How to activate Kuna Code via API?

The essence of the problem is that through the api I am trying to activate the so-called Kuna Code, which activates the translation,

import requests
import time
import hmac
import hashlib

secret_key = '' # здесь все указываем
public_key = '' # здесь все указываем

url = "https://api.kuna.io/v3/auth/kuna_codes/redeem"
api_path = "/v3/auth/kuna_codes/redeem"

rs = 'https://api.kuna.io/v3/auth/me'    
api_paths = "/v3/auth/me"

body = ''
nonce = str(int(time.time()*1000.0)) 
body = str('')
msg = api_paths+nonce+body
print(msg)
kun_signature = hmac.new(secret_key.encode('ascii'), msg.encode('ascii'), hashlib.sha384).hexdigest()

headers = {
    "Accept": "application/json",
    "Content-Type": "application/json",
    'kun-nonce': nonce,
    'kun-apikey': public_key,
    'kun-signature': kun_signature
}

pool = requests.post(rs, headers=headers)
print(pool.text)
codein = {"code": ""}
response = requests.request("PUT", url, json=codein, headers=headers) #активация кода
print(response.text)

Authorization is successful and data with email and other data is displayed, but after that
an error like
{"messages":["the_tonce_has_already_been_used_by_access_key"]}

What am I doing wrong? I also tried to change the headers to different ones, and in this case an error like signature_is_incorrect gets out, all to no avail. That is, authorization is successful, and the second request throws an error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dimonchik, 2021-05-15
@dimonchik2013

nanchi from Postman, run the browser 2-3 times and track the whole sequence

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question