I'm sure there's a really simple solution to this, but I'm still fairly new to Python.
I'm trying to use dateutil.parser.parse() to parse a string with a timestamp in it:
>>> import dateutil.parser
>>> a = dateutil.parser.parse("2011-10-01 12:00:00+01:00")
>>> print a
2011-10-01 12:00:00+01:00
This works fine on my Linux server, but on my Windows test box it gives an error:
>>> import dateutil.parser
>>> a = dateutil.parser.parse("2011-10-01 12:00:00+01:00")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\python_dateutil-2.0-py2.7.egg\dateutil\parser.py", line 698, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "C:\Python27\lib\site-packages\python_dateutil-2.0-py2.7.egg\dateutil\parser.py", line 302, in parse
res = self._parse(timestr, **kwargs)
File "C:\Python27\lib\site-packages\python_dateutil-2.0-py2.7.egg\dateutil\parser.py", line 350, in _parse
l = _timelex.split(timestr)
File "C:\Python27\lib\site-packages\python_dateutil-2.0-py2.7.egg\dateutil\parser.py", line 144, in split
return list(cls(s))
File "C:\Python27\lib\site-packages\python_dateutil-2.0-py2.7.egg\dateutil\parser.py", line 44, in __init__
instream = StringIO(instream)
TypeError: initial_value must be unicode or None, not str
If I try giving dateutil.parser.parse() a unicode string, that doesn't work on the Windows box either:
>>> a = dateutil.parser.parse(unicode("2011-10-01 12:00:00+01:00"))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\python_dateutil-2.0-py2.7.egg\dateutil\parser.py", line 698, in parse
return DEFAULTPARSER.parse(timestr, **kwargs)
File "C:\Python27\lib\site-packages\python_dateutil-2.0-py2.7.egg\dateutil\parser.py", line 302, in parse
res = self._parse(timestr, **kwargs)
File "C:\Python27\lib\site-packages\python_dateutil-2.0-py2.7.egg\dateutil\parser.py", line 350, in _parse
l = _timelex.split(timestr)
File "C:\Python27\lib\site-packages\python_dateutil-2.0-py2.7.egg\dateutil\parser.py", line 144, in split
return list(cls(s))
TypeError: iter() returned non-iterator of type '_timelex'
Yet this also works on the Linux box.