1 year ago

#386337

test-img

dannyclark

"OverflowError: mktime argument out of range" on python:3 docker image

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?

python

docker

mktime

0 Answers

Your Answer

Accepted video resources