[issue19208] Bas64.decodestring() returns data instead of throwing exception

R. David Murray report at bugs.python.org
Wed Oct 9 19:58:13 CEST 2013


R. David Murray added the comment:

You are looking for the (new in Python 3) 'validate' option of b64decode:

>>> base64.b64decode(b"GET http://www.google.com.hk/search?q=hotels+near+airport&pws=1&igu=1&ip=0.0.0.0&safe=images&gl=CN&gll=39.913889,116.391667&near=china&hl=zh-CN", validate=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/rdmurray/python/p34/Lib/base64.py", line 87, in b64decode
    raise binascii.Error('Non-base64 digit found')
binascii.Error: Non-base64 digit found

In Python2, the base64 module unfortunately only handles the applications of RFC 3548 where non-base64 alphabet characters are required to be ignored.  (Those are (or were?) the primary applications of the RFC, by the way, which is why it was implemented that way originally.)

----------
nosy: +r.david.murray
resolution:  -> out of date
stage:  -> committed/rejected
status: open -> closed

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19208>
_______________________________________


More information about the Python-bugs-list mailing list