I'm validating some functions created in python, I have a code that creates some functions. When I run the program with the functions (test_client.py), I get run-time error. auth_utils.py:
from hashlib import sha256
try:
from urllib import urlencode
except ImportError:
from urllib.parse import urlencode
def create_signature(secret_key, data=None):
if data is None:
data = {}
url_encoded_data = urlencode(sorted(data.items()))
hashed_data = sha256(secret_key + url_encoded_data)
return hashed_data.hexdigest()
test_client.py:
from auth_utils import create_signature
from time import time
API_KEY = "kaakAYJ58EouuGW2"
API_SECRET = "HRN4Ig7BMB8xY9qVLJA7Ylzy"
DATA = {
'first_name': 'Jonh',
execution error:
$ python test_headers.py Traceback (most recent call last): File "test_headers.py", line 13, in header="Authorization Voxy {}: {}". format (API_KEY, create_signature (API_SECRET, DATA)) File "F: \ xampp \ htdocs \ proj \ voxy \ auth_utils.py", line 12, in create_signature hashed_data = sha256 (secret_key + url_encoded_data) TypeError: Unicode-objects must be encoded before hashing