HeaderParseError
Thomas Guettler
hv at tbz-pariv.de
Mon Jul 4 06:38:39 EDT 2011
On 04.07.2011 11:51, Peter Otten wrote:
> 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?
Hi Peter, Thunderbird shows this:
Anmeldung Netzanschluss Südring3p.jpg
Thomas
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
More information about the Python-list
mailing list