[Django]-Django dateutil ISO 8601 no 'read' attribute error

5πŸ‘

βœ…

I can reproduce the error message like this:

In [58]: import datetime as DT

In [59]: eventdate = DT.datetime(2013, 6, 18, 2, 50)
In [60]: print(eventdate)
2013-06-18 02:50:00

In [61]: import dateutil.parser as parser
In [62]: parser.parse(eventdate)
AttributeError: 'datetime.datetime' object has no attribute 'read'

So on this basis it seems as though eventdate is probably already a datetime.datetime object. If so, there is no need to call

date_iso = dateutil.parser.parse(eventdate)

To convert it to a string in ISO8601 format, use

In [66]: eventdate.isoformat()
Out[66]: '2013-06-18T02:50:00'
πŸ‘€unutbu

0πŸ‘

The error is quite clear: you’re passing in a datetime object when in fact parse expects a string.

Leave a comment