You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IsADirectoryError while getting local timezone #256
Traceback (most recent call last):
File "test.py", line 2, in <module>
pendulum.now()
File "/mnt/iscsi/10_web_cem_dev/work/axc/cem-one-times/env/lib64/python3.6/site-packages/pendulum/__init__.py", line 207, in now
dt = _datetime.datetime.now(local_timezone())
File "/mnt/iscsi/10_web_cem_dev/work/axc/cem-one-times/env/lib64/python3.6/site-packages/pendulum/tz/__init__.py", line 59, in local_timezone
return get_local_timezone()
File "/mnt/iscsi/10_web_cem_dev/work/axc/cem-one-times/env/lib64/python3.6/site-packages/pendulum/tz/local_timezone.py", line 31, in get_local_timezone
tz = _get_system_timezone()
File "/mnt/iscsi/10_web_cem_dev/work/axc/cem-one-times/env/lib64/python3.6/site-packages/pendulum/tz/local_timezone.py", line 59, in _get_system_timezone
return _get_unix_timezone()
File "/mnt/iscsi/10_web_cem_dev/work/axc/cem-one-times/env/lib64/python3.6/site-packages/pendulum/tz/local_timezone.py", line 210, in _get_unix_timezone
return Timezone('/'.join(tzpath))
File "/mnt/iscsi/10_web_cem_dev/work/axc/cem-one-times/env/lib64/python3.6/site-packages/pendulum/tz/timezone.py", line 30, in __init__
tz = read(name, extend=extended)
File "/mnt/iscsi/10_web_cem_dev/work/axc/cem-one-times/env/lib64/python3.6/site-packages/pendulum/tz/zoneinfo/__init__.py", line 9, in read
return Reader(extend=extend).read_for(name)
File "/mnt/iscsi/10_web_cem_dev/work/axc/cem-one-times/env/lib64/python3.6/site-packages/pendulum/tz/zoneinfo/reader.py", line 52, in read_for
return self.read(file_path)
File "/mnt/iscsi/10_web_cem_dev/work/axc/cem-one-times/env/lib64/python3.6/site-packages/pendulum/tz/zoneinfo/reader.py", line 63, in read
with open(file_path, 'rb') as fd:
IsADirectoryError: [Errno 21] Is a directory: '/mnt/iscsi/10_web_cem_dev/work/axc/cem-one-times/env/lib64/python3.6/site-packages/pytzdata/zoneinfo/Pacific'
This is the content of my /etc/sysconfig/clock:
ZONE="US/Pacific"
I think it should be trying to read env/lib64/python3.6/site-packages/pytzdata/zoneinfo/US/Pacific
I just got a similar error: IsADirectoryError: [Errno 21] Is a directory: '/etc/timezone'
and found an empty directory at /etc/timezone/ which shouldn't be there, I deleted the directory to handle the error, but pendulum should be more careful with files.
Activity
aczapszys commentedon Jul 23, 2018
I can confirm
test.pyworks w/ pendulum 2.0.0, but not with 2.0.1 - 2.0.4leric commentedon Aug 7, 2019
I just got a similar error:
IsADirectoryError: [Errno 21] Is a directory: '/etc/timezone'and found an empty directory at /etc/timezone/ which shouldn't be there, I deleted the directory to handle the error, but pendulum should be more careful with files.
Don't attempt to open a directory as a tz file
Merge pull request #594 from beci/master
lsh-0 commentedon Sep 2, 2022
The fix looks like it's here: sdispater/pytzdata#11
But it's uncommitted.
Could it be committed please? alternately, could this ticket be re-opened?
I had the same problem as @leric .
update: my mistake, Github reports the fix is here #594 and was merged Jan 7th 2022, however there hasn't been a release since https://github.com/sdispater/pendulum/releases/tag/2.1.2 in July 2020. Could pendulum get a release, please?
darkfeline commentedon May 23, 2024
I'm seeing this on pendulum-3.0.0 (as a dep for flexget). Was the bug fixed or did this regress?
aczapszys commentedon May 24, 2024
@darkfeline
I think what you're seeing is an edge case that was not fixed. You might want to open a new issue with your stack trace / description.
I presume that in your case,
/etc/localtimeis a symlink to something like/usr/share/zoneinfo/US/Pacific.In that case,
_get_unix_timezonecallsTimezone("Pacific")to see if it's valid.https://github.com/sdispater/pendulum/blob/3.0.0/src/pendulum/tz/local_timezone.py#L232
However, down in Python's
zoneinfo.load_tzdata, it does not protect against its resource maybe being a directory (https://github.com/python/tzdata/tree/master/src/tzdata/zoneinfo/Pacific). It throws anIsADirectoryErrorwhere it should have thrown aZoneInfoNotFoundError.https://github.com/python/cpython/blame/main/Lib/zoneinfo/_common.py#L13
Ideally, this fix would go in
zoneinfo. But in the mean time, you could addIsADirectoryErrorto_get_unix_timezone'scontextlib.suppresscall.