Skip to content
Advertisement

Django user activation doesnt work with token — TypeError: a bytes-like object is required, not ‘str’

So I have the following token activation setup for users to activate their accounts

JavaScript
JavaScript
JavaScript
JavaScript

However, when I click the emailed link, the view always returns the isn't valid path. Some debugging pointed me to print(User.objects.get(pk=uid)) which returns

TypeError: a bytes-like object is required, not ‘str’ [01/Sep/2022 04:18:57] “GET /activate/MjA1ZjJjOWUtZjJmZC00ZDNlLWI5ZjktMTFiYjJiMzBkYWRm/bb210r-cb574367d34da4d3175ab454a49e6527/ HTTP/1.1” 500 132326

Not sure what’s wrong as this setup already worked in a different project of mine.

Advertisement

Answer

probably you are need force_str more here: https://docs.djangoproject.com/en/4.1/ref/utils/#django.utils.encoding.force_str

in your case:

JavaScript

more here: https://docs.python.org/3/library/stdtypes.html#bytes.decode

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement