M
M
Martin_Shelby2020-06-08 20:20:53
Python
Martin_Shelby, 2020-06-08 20:20:53

How to make a verification signature?

Please help me figure it out. I recently started to study the anypay.io API and got stuck at the very start :) When reproducing the code:

import requests
import hashlib
from data import ANYPAY_API_ID, ANYPAY_API_KEY
import json

sign = hashlib.sha256(f'balance{ANYPAY_API_ID()}{ANYPAY_API_KEY()}'.encode())
responce = requests.get(f"https://anypay.io/api/balance/{ANYPAY_API_ID()}", params=str(sign))
print(responce.json())

i get error 102:
{'error': {'code': '102', 'message': 'Invalid sign'}}

Based on the documentation ( https://anypay.io/doc/api/errors) , I found out that the problem is an incorrect control signature, but I have already broken my head and cannot figure out where I made a mistake.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dr. Bacon, 2020-06-08
@bacon

Usually also done in hexadecimal format, apply hexdigest to sign

G
galaxy, 2020-06-08
@galaxy

Have you looked in the console to see what str(hashlib.sha256(...)) will output?
And it will display something like: '<sha256 HASH object @ 0x6ffffebcc88>'
As written above, you need to sign.digest() or sign.hexdigest(), depending on what form the api wants.
Well, it’s unlikely that a naked signature is put in POST, judging by the dock, you need something like:

requests.get(..., params={"sign":sign.hexdigest()})

Or maybe you need to pass parameters in json.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question