Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AttributeError: 'str' object has no attribute 'decode' || related to django user creation

Tags:

django

I am getting the following error:

AttributeError: 'str' object has no attribute 'decode'

This is my code:

from django.utils.encoding import force_bytes
from django.utils.http import urlsafe_base64_encode
seld.uid = urlsafe_base64_encode(force_bytes(user.pk)).decode()`
like image 574
yogesh Avatar asked Oct 22 '25 04:10

yogesh


1 Answers

Since Django 2.2, urlsafe_base64_encode returns a string instead of bytes, so you should no longer call the decode method anymore:

seld.uid = urlsafe_base64_encode(force_bytes(user.pk))
like image 126
blhsing Avatar answered Oct 23 '25 19:10

blhsing