HeaderParseError
Peter Otten
__peter__ at web.de
Mon Jul 4 05:51:41 EDT 2011
Thomas Guettler wrote:
> I get a HeaderParseError during decode_header(), but Thunderbird can
> display the name.
>
>>>> from email.header import decode_header
>>>>
decode_header('=?iso-8859-1?B?QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?=')
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib64/python2.6/email/header.py", line 101, in decode_header
> raise HeaderParseError
> email.errors.HeaderParseError
>
>
> How can I parse this in Python?
Trying to decode as much as possible:
>>> s = "QW5tZWxkdW5nIE5ldHphbnNjaGx1c3MgU_xkcmluZzNwLmpwZw==?="
>>> for n in range(len(s), 0, -1):
... try: t = s[:n].decode("base64")
... except: pass
... else: break
...
>>> n, t
(49, 'Anmeldung Netzanschluss S\x19\x1c\x9a[\x99\xcc\xdc\x0b\x9a\x9c\x19')
>>> print t.decode("iso-8859-1")
Anmeldung Netzanschluss S[ÌÜ
>>> s[n:]
'w==?='
The characters after "...Netzanschluss " look like garbage. What does
Thunderbird display?
More information about the Python-list
mailing list