binascii.Error: Invaild base64-encoded string: number of data characters(1957) cannot be 1 more than a multiple of 4
Solution 1:
-
Try padding your input with the correct number (1,2 or 3) of
=
characters so as to make its final length a multiple of 4. Skip that step if your token length is already a multiple of 4 (len(padded_token)%4 == 0
). -
You might get the same error still if your input is using characters
-_
in which case it means it is urlsafe encoded. In that case usebase64.urlsafe_b64decode
rather thanbase64.b64decode
to decode it.
Solution 2:
I've also got this error because of modifying a session cookie. When I accessed the django server(localhost:8000) via chrome, i got this error but then using incognito mode, it worked.
The solution was to clear my cookies. I hope that helps somebody!