#34891 closed Bug (invalid)
force_str(urlsafe_base64_decode(uidb64)) returns object not value — at Version 1
Reported by: | Jeff Lovern | Owned by: | nobody |
---|---|---|---|
Component: | Utilities | Version: | 4.2 |
Severity: | Normal | Keywords: | django.utils.encoding |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
>>> from django.utils.encoding import force_str >>> from django.utils.http import urlsafe_base64_decode >>> uidb64 = 'PHByb3BlcnR5IG9iamVjdCBhdCAweDAwMDAwMjU1M0ZBNTlEQTA-bvlp6u-9b15d1fd6d30b90e81623812e9bc8d74' >>> result = urlsafe_base64_decode(uidb64) >>> result b'<property object at 0x000002553FA59DA0>n\xf9i\xea\xef\xbdo^]\xd5\xf7zw}\x1b\xf7G\xbc\xd7\xad\xb7\xf3]\x9e\xf5\xb7<w\xbe' >>> force_str(result) Traceback (most recent call last): File "/home/tim/code/django/django/utils/encoding.py", line 70, in force_str s = str(s, encoding, errors) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf9 in position 40: invalid start byte During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<console>", line 1, in <module> File "/home/tim/code/django/django/utils/encoding.py", line 74, in force_str raise DjangoUnicodeDecodeError(s, *e.args) django.utils.encoding.DjangoUnicodeDecodeError: 'utf-8' codec can't decode byte 0xf9 in position 40: invalid start byte. You passed in b'<property object at 0x000002553FA59DA0>n\xf9i\xea\xef\xbdo^]\xd5\xf7zw}\x1b\xf7G\xbc\xd7\xad\xb7\xf3]\x9e\xf5\xb7<w\xbe' (<class 'bytes'>)
Code:
def activate(request, uidb64, token): try: uid = force_str(urlsafe_base64_decode(uidb64)) user = CustomUser.objects.get(pk=uid) except (TypeError, ValueError, OverflowError, CustomUser.DoesNotExist): user = None if user is not None and account_activation_token.check_token(user, token): user.is_active = True user.save() login(request, user) return redirect('account_activation_complete') else: return HttpResponseBadRequest('Activation link is invalid!')
Change History (1)
comment:1 by , 13 months ago
Description: | modified (diff) |
---|---|
Resolution: | → needsinfo |
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Hi Jeff, it's unclear that Django is at fault here. It looks like the
uidb64
value isn't correct for what this code is trying to do. See TicketClosingReasons/UseSupportChannels if you need help debugging your issue, and reopen the ticket if you can explain why Django is at fault. Thanks!