“溢出错误:mktime 参数超出范围”在 python:3 docker 镜像上
我正在使用time.mktime()以某种格式获得使用第三方API的日期。
我可以在Python上重现一个溢出错误:3座图像,我在Ubuntu Lts上本地运行时看不到这一点(20.04)
>>> import pytz
>>> import datetime
>>> import time
>>> time.mktime(pytz.timezone('Europe/London').localize(datetime.datetime(2022, 3, 29)).timetuple())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: mktime argument out of range
2022年3月27日以上的日期似乎在欧洲/伦敦时区似乎都在给我,但是我不要以为这是遇到任何32位整数限制的限制,因为这将在2038年预期。
首先转换为UTC TighZone可以通过一个简单的解决方法。
>>> time.mktime(pytz.timezone('Europe/London').localize(datetime.datetime(2022, 3, 29)).astimezone(pytz.UTC).timetuple())
1648508400.0
为什么要溢出?如果是一个错误,那么在哪里报告它是什么?
I'm using time.mktime() to get dates in a certain format to use a 3rd-party API.
I can reproduce an overflow error on the python:3 docker images, which I don't see when running locally on ubuntu LTS (20.04)
>>> import pytz
>>> import datetime
>>> import time
>>> time.mktime(pytz.timezone('Europe/London').localize(datetime.datetime(2022, 3, 29)).timetuple())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OverflowError: mktime argument out of range
Any dates greater than 27 March 2022 seem to give this year for the Europe/London timezone, but I don't think this is hitting any 32-bit integer limit yet, as that would be expected in the year 2038.
There's a simple workaround by first converting to the UTC timezone.
>>> time.mktime(pytz.timezone('Europe/London').localize(datetime.datetime(2022, 3, 29)).astimezone(pytz.UTC).timetuple())
1648508400.0
Why does this overflow? If it's a bug, where's the best place to report it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论