-1

Python2 wotking but py3 not working

hashlib.sha256(re.sub('[^a-zA-Z0-9]', "", each_user["Merchandiser"]).lower()[
                                           :4].capitalize() + "@123").hexdigest()
ForceBru
  • 36,993
  • 10
  • 54
  • 78

2 Answers2

1

You need to encode the string before you call hexdigest.

Try the following:

import hashlib

hashlib.sha256(
    (
        re.sub('[^a-zA-Z0-9]', "", each_user["Merchandiser"]
              ).lower()[:4].capitalize() + "@123"
    ).encode("utf-8")
).hexdigest()
Benjamin Rowell
  • 1,216
  • 7
  • 16
1

what type is 'each_user' here?

I think your need to encode sha256 argument

hashlib.sha256((re.sub('[^a-zA-Z0-9]', "", each_user["Merchandiser"]).lower()[:4].capitalize() + "@123").encode())

if

each_user["Merchandiser"]

is a str

nouret
  • 11
  • 5