Martin Panter added the comment:

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__)

----------
nosy: +martin.panter
title: int no attribute 'lower' -> int no attribute 'lower' iterating 
email.Messasge

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28881>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to