gpt4 book ai didi

python dateutil unicode警告

转载 作者:太空狗 更新时间:2023-10-29 22:26:32 25 4
gpt4 key购买 nike

我正在使用 sixohsix 库从 Twitter API 解析一些推文数据。我正在尝试将推文的日期转换为我的语言环境:

from pytz import timezone
from dateutil import parser

timestamp = parser.parse(tweet["created_at"])
timestamp_arg = timestamp.astimezone(timezone('America/Buenos_Aires'))

我收到一个 unicode 警告:

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:

我试过

parser.parse(str(tweet["created_at"]))
parser.parse(unicode(tweet["created_at"]).encode())

但是什么都没有改变。

除了警告之外似乎没有任何问题。有谁知道为什么会这样,以及如何解决?

谢谢!

更新:

我尝试了相同的示例,但将时间硬编码为字符串,并且在没有警告的情况下工作。另外根据警告消息,问题似乎发生在解析调用中,在 parser.py:339 执行

res.tzname in time.tzname

可能是因为 res 是 unicode 而 time.tzname 不是??

最佳答案

这是 dateutil(从版本 2.2 开始)中的一个 Unresolved 错误,它只发生在 Windows 上:https://bugs.launchpad.net/dateutil/+bug/1227221

除非您尝试使用非 ascii 字符解析时区,否则 Dateutil 仍将正常运行。我认为这很不寻常,所以你应该没问题。

最简单的解决方法可能就是消除错误。

import warnings
warnings.filterwarnings("ignore", category=UnicodeWarning)

关于python dateutil unicode警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21296475/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com