im parsing some tweet's data from Twitter API using sixohsix library. Im trying to convert the date of the tweet to my locale:
from pytz import timezone
from dateutil import parser
timestamp = parser.parse(tweet["created_at"])
timestamp_arg = timestamp.astimezone(timezone('America/Buenos_Aires'))
and im getting a unicode warning:
dateutil\parser.py:339: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal elif res.tzname and res.tzname in time.tzname:
I've tried doing
parser.parse(str(tweet["created_at"]))
parser.parse(unicode(tweet["created_at"]).encode())
But nothing changes.
Besides the warning nothing seems to be broken. Does anyone know why is this happening, and how to fix it?
Thanks!
I've tried the same example but hardcoding the time to string and that works without the warning. Also according to the warning msg the issue seems to happen in the parse call, in parser.py:339 when doing
res.tzname in time.tzname
maybe because res is unicode and time.tzname is not??
This is an unsolved bug in dateutil (as of version 2.2) that only occur on Windows: https://bugs.launchpad.net/dateutil/+bug/1227221
Dateutil will still behave correctly unless you try to parse timezones with non-ascii-characters. I assume this is very unusual, so you should be fine.
The easiest workaround is probably just to silence the errors.
import warnings
warnings.filterwarnings("ignore", category=UnicodeWarning)
Only 18 month after the question and 15 month after the answer, we have probably solved this bug: https://github.com/dateutil/dateutil/issues/92
So the current solution is to upgrade to the development version of dateutil
or any version >=2.5.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With