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!
UPDATE:
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??
u'America/Buenos_Aires'
– Meteorologyencode()
at the end is unlikely to help anything, since the warning has obviously already happened before you get that far. And generally, just callingstr
orunicode
on things without an encoding is a very bad idea, especially things that came off the internet and therefore are likely to have a different encoding than your system's default. – Prewardateutil
, it's usually worth mentioning the version. Especially in the case of a library that's relatively recently been ported to dual-2.x/3.x-compatible code, and could easily have had a bug in the version you have that was fixed the next day. – Prewar