[New-bugs-announce] [issue12241] email.header.Header encoding fails on empty header

Tim Koopman report at bugs.python.org
Thu Jun 2 17:25:14 CEST 2011

New submission from Tim Koopman <python.org at nandoe.net>:

Creating an empty header produces an exception when calling the encode function:

>>> from email.header import Header
>>> Header('', 'iso-8859-1').encode()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.2/email/header.py", line 317, in encode
    formatter.feed(lines[0], charset)
IndexError: list index out of range

According to RFC822, empty headers are valid (and are found in the wild anyway), so this should just work.

I've attached a trivial fix that appears to work.

components: Library (Lib)
files: header.patch
keywords: patch
messages: 137480
nosy: ntkoopman
priority: normal
severity: normal
status: open
title: email.header.Header encoding fails on empty header
type: behavior
versions: Python 3.2
Added file: http://bugs.python.org/file22221/header.patch

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list