This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients Vitold S, barry, martin.panter, r.david.murray
Date 2016-12-05.21:13:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1480972397.14.0.133491206562.issue28881@psf.upfronthosting.co.za>
In-reply-to
Content
You just need a messsage object with one or more header fields:

>>> msg = message_from_string("Name: value\r\n\r\n")
>>> for m in msg:
...     pass
... 
AttributeError: 'int' object has no attribute 'lower'

Python 2 does not implement __iter__(), so it is the default sequence iteration protocol causing this behaviour. The documentation does not mention iteration either: <https://docs.python.org/2.7/library/email.message.html#email.message.Message.__len__>. It mentions a “mapping-like interface”, but since it explicitly lists __len__(), __contains__(), etc, and not __iter__(), I would say you should not assume iteration is supported.

Python 3 does implement Message.__iter__(), but it does not seem to be documented. The method seems to be added as a side effect of Guido removing and restoring the email package:

https://github.com/python/cpython/commit/1058618#diff-92a78c52ebc0a8908cbd06c8155f8bdb (removed without __iter__)
https://hg.python.org/cpython/file/d5f3c2f416f2/Lib/email/message.py (added back including __iter__)
History
Date User Action Args
2016-12-05 21:13:17martin.pantersetrecipients: + martin.panter, barry, r.david.murray, Vitold S
2016-12-05 21:13:17martin.pantersetmessageid: <1480972397.14.0.133491206562.issue28881@psf.upfronthosting.co.za>
2016-12-05 21:13:17martin.panterlinkissue28881 messages
2016-12-05 21:13:16martin.pantercreate