Python3.3 email policy date field

H

Helmut Jarausch

Hi,

in response to a bug report I got the follow helpful comments from R. David Murray.
Many thanks to him. (Unfortunately, I don't know his email, so I can write him directly)

To generate an email (with non-ascii letters)

R. David Murray said:
But even better, so will this:
m = Message(policy=policy.SMTP)
m['From'] = "Günter Weiße <[email protected]>"




This works, but now I cannot add a date field

Trying

m['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p')

I get

Traceback (most recent call last):
File "Test_EMail_Py3_4.py", line 23, in <module>
msg['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p')
File "/usr/lib64/python3.3/email/message.py", line 359, in __setitem__
self._headers.append(self.policy.header_store_parse(name, val))
File "/usr/lib64/python3.3/email/policy.py", line 119, in header_store_parse
return (name, self.header_factory(name, value))
File "/usr/lib64/python3.3/email/headerregistry.py", line 583, in __call__
return self[name](name, value)
File "/usr/lib64/python3.3/email/headerregistry.py", line 194, in __new__
cls.parse(value, kwds)
File "/usr/lib64/python3.3/email/headerregistry.py", line 300, in parse
value = utils.parsedate_to_datetime(value)
File "/usr/lib64/python3.3/email/utils.py", line 243, in parsedate_to_datetime
*dtuple, tz = __parsedate_tz(data)
TypeError: 'NoneType' object is not iterable


Many thanks for a hint,
Helmut.
 
M

MRAB

Hi,

in response to a bug report I got the follow helpful comments from R. David Murray.
Many thanks to him. (Unfortunately, I don't know his email, so I can write him directly)

To generate an email (with non-ascii letters)

R. David Murray said:
But even better, so will this:
m = Message(policy=policy.SMTP)
m['From'] = "Günter Weiße <[email protected]>"




This works, but now I cannot add a date field

Trying

m['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p')

I get

Traceback (most recent call last):
File "Test_EMail_Py3_4.py", line 23, in <module>
msg['Date'] = datetime.datetime.utcnow().strftime('%m/%d/%Y %I:%M:%S %p')
File "/usr/lib64/python3.3/email/message.py", line 359, in __setitem__
self._headers.append(self.policy.header_store_parse(name, val))
File "/usr/lib64/python3.3/email/policy.py", line 119, in header_store_parse
return (name, self.header_factory(name, value))
File "/usr/lib64/python3.3/email/headerregistry.py", line 583, in __call__
return self[name](name, value)
File "/usr/lib64/python3.3/email/headerregistry.py", line 194, in __new__
cls.parse(value, kwds)
File "/usr/lib64/python3.3/email/headerregistry.py", line 300, in parse
value = utils.parsedate_to_datetime(value)
File "/usr/lib64/python3.3/email/utils.py", line 243, in parsedate_to_datetime
*dtuple, tz = __parsedate_tz(data)
TypeError: 'NoneType' object is not iterable
From what I've tried, it looks like the date can't be a string:
m['Date'] = datetime.datetime.utcnow()
m['Date']
'Thu, 23 Aug 2012 11:33:20 -0000'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top