Message325757
The following error message in Python 3.7 is confusing and unhelpful:
>>> s = "FS9qzW_oliGH_Yo="
>>> base64.b64decode(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Invalid base64-encoded string: length cannot be 1 more than a multiple of 4
>>> len(s) % 4
0
This had me staring at the string s and scratching my head, thinking: "s doesn't have length 1 more than a multiple of 4, either with or without the "=" padding byte. What's this talking about?"
The actual user error here is a failure to use the "altchars" argument correctly:
>>> base64.b64decode(s, altchars="-_")
b'\x15/j\xcdo\xe8\x96!\x87\xfd\x8a'
The error message in versions prior to Python 3.7 is no more helpful, but it's not quite as misleading, either.
Python 3.6.6 (default, Jun 28 2018, 05:43:53)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import base64
>>> s = "FS9qzW_oliGH_Yo="
>>> base64.b64decode(s)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/base64.py", line 87, in b64decode
return binascii.a2b_base64(s)
binascii.Error: Incorrect padding
Related: #1466065, #33770 |
|
Date |
User |
Action |
Args |
2018-09-19 13:00:53 | mark.dickinson | set | recipients:
+ mark.dickinson |
2018-09-19 13:00:53 | mark.dickinson | set | messageid: <1537362053.96.0.956365154283.issue34736@psf.upfronthosting.co.za> |
2018-09-19 13:00:53 | mark.dickinson | link | issue34736 messages |
2018-09-19 13:00:53 | mark.dickinson | create | |
|