Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #8765

Re: HeaderParseError

From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: HeaderParseError
Followup-To comp.lang.python
Date 2011-07-04 11:51 +0200
Organization None
Message-ID <ius2f9$e1$1@solani.org> (permalink)
References <97dc37F7gaU1@mid.individual.net>

Followups directed to: comp.lang.python

Show all headers | View raw


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?

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

HeaderParseError Thomas Guettler <hv@tbz-pariv.de> - 2011-07-04 10:31 +0200
  Re: HeaderParseError Peter Otten <__peter__@web.de> - 2011-07-04 11:51 +0200
    Re: HeaderParseError Thomas Guettler <hv@tbz-pariv.de> - 2011-07-04 12:38 +0200
      Re: HeaderParseError Peter Otten <__peter__@web.de> - 2011-07-04 13:20 +0200
        Re: HeaderParseError Thomas Guettler <hv@tbz-pariv.de> - 2011-07-05 14:02 +0200

csiph-web