1
I’m validating some functions created in python, I have a code that creates some functions. When running the program with the functions (test_client.py), I get an 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',
error in execution:
$ 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
I just didn’t understand the title of the question: what did you mean by "references are not available in the final program"?
– Woss