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


Groups > comp.lang.python > #27708 > unrolled thread

Python3.3 email policy date field

Started byHelmut Jarausch <jarausch@igpm.rwth-aachen.de>
First post2012-08-23 08:30 +0000
Last post2012-08-23 12:30 +0000
Articles 3 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  Python3.3 email policy date field Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2012-08-23 08:30 +0000
    Re: Python3.3 email policy date field MRAB <python@mrabarnett.plus.com> - 2012-08-23 12:36 +0100
      Re: Python3.3 email policy date field Helmut Jarausch <jarausch@igpm.rwth-aachen.de> - 2012-08-23 12:30 +0000

#27708 — Python3.3 email policy date field

FromHelmut Jarausch <jarausch@igpm.rwth-aachen.de>
Date2012-08-23 08:30 +0000
SubjectPython3.3 email policy date field
Message-ID<a9m80dF896U1@mid.dfncis.de>
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 wrote:

>>> But even better, so will this:

>>> m = Message(policy=policy.SMTP)
>>> m['From'] = "Günter Weiße <jarausch@igpm.rwth-aachen.de>"




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.

[toc] | [next] | [standalone]


#27727

FromMRAB <python@mrabarnett.plus.com>
Date2012-08-23 12:36 +0100
Message-ID<mailman.3712.1345721756.4697.python-list@python.org>
In reply to#27708
On 23/08/2012 09:30, Helmut Jarausch wrote:
> 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 wrote:
>
>>>> But even better, so will this:
>
>>>> m = Message(policy=policy.SMTP)
>>>> m['From'] = "Günter Weiße <jarausch@igpm.rwth-aachen.de>"
>
>
>
>
> 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'

[toc] | [prev] | [next] | [standalone]


#27729

FromHelmut Jarausch <jarausch@igpm.rwth-aachen.de>
Date2012-08-23 12:30 +0000
Message-ID<a9mm3cF896U2@mid.dfncis.de>
In reply to#27727
On Thu, 23 Aug 2012 12:36:01 +0100, MRAB wrote:
>  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'

Many thanks - it's even easier!

Waiting for Python 3.3 to become standard!

Helmut.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web