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
zoneinfo: ZoneInfo raises IsADirectoryError instead of ZoneInfoNotFoundError #85702
About the permission error, how did you install tzdata? Did you install it as an admin user and do you run Python as a different user?
bijij commented on Aug 12, 2020
bijijmannequin
MannequinAuthor
More actions
tzdata was installed as an admin user, however this behaviour was
reproducible on a linux installation where for the ZoneInfo.('Pacific')
instance an IsADirectoryError would instead be raised.
# ZoneInfoNotFoundError expected, get IsADirectoryError
>>> import zoneinfo; zoneinfo.ZoneInfo('Pacific')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vstinner/python/master/Lib/zoneinfo/_common.py", line 12, in load_tzdata
return importlib.resources.open_binary(package_name, resource_name)
File "/home/vstinner/python/master/Lib/importlib/resources.py", line 40, in open_binary
return reader.open_resource(resource)
File "/home/vstinner/python/master/Lib/importlib/abc.py", line 419, in open_resource
return self.files().joinpath(resource).open('rb')
File "/home/vstinner/python/master/Lib/pathlib.py", line 1238, in open
return io.open(self, mode, buffering, encoding, errors, newline,
IsADirectoryError: [Errno 21] Is a directory: '/home/vstinner/python/master/env/lib/python3.10/site-packages/tzdata/zoneinfo/Pacific'
# valid zone
>>> import zoneinfo; zoneinfo.ZoneInfo('Pacific/Noumea')
zoneinfo.ZoneInfo(key='Pacific/Noumea')
# raise ZoneInfoNotFoundError as expected (from FileNotFoundError)
>>> import zoneinfo; zoneinfo.ZoneInfo('xxx')
Traceback (most recent call last):
File "/home/vstinner/python/master/Lib/zoneinfo/_common.py", line 12, in load_tzdata
return importlib.resources.open_binary(package_name, resource_name)
File "/home/vstinner/python/master/Lib/importlib/resources.py", line 40, in open_binary
return reader.open_resource(resource)
File "/home/vstinner/python/master/Lib/importlib/abc.py", line 419, in open_resource
return self.files().joinpath(resource).open('rb')
File "/home/vstinner/python/master/Lib/pathlib.py", line 1238, in open
return io.open(self, mode, buffering, encoding, errors, newline,
File "/home/vstinner/python/master/Lib/pathlib.py", line 1106, in _opener
return self._accessor.open(self, flags, mode)
FileNotFoundError: [Errno 2] No such file or directory: '/home/vstinner/python/master/env/lib/python3.10/site-packages/tzdata/zoneinfo/xxx'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/vstinner/python/master/Lib/zoneinfo/_common.py", line 24, in load_tzdata
raise ZoneInfoNotFoundError(f"No time zone found with key {key}")
zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key xxx'
changed the title [-]Unhandled exceptions in zoneinfo.ZoneInfo constructor[/-][+]zoneinfo: ZoneInfo raises IsADirectoryError instead of ZoneInfoNotFoundError[/+]on Aug 12, 2020
changed the title [-]Unhandled exceptions in zoneinfo.ZoneInfo constructor[/-][+]zoneinfo: ZoneInfo raises IsADirectoryError instead of ZoneInfoNotFoundError[/+]on Aug 12, 2020
On Linux, converting IsADirectoryError to ZoneInfoNotFoundError is easy.
But on Windows, I don't think that converting any PermissionError into a ZoneInfoNotFoundError is a good idea. Maybe if PermissionError happens, we should check if the path is a directory.
Pseudo-code:
try:
<open and read file>
except OSError as exc:
if os.path.isdir(zone_path):
raise ZoneInfoNotFoundError
else:
raise
Windows pr and backports have been merged. I do not know of anything else to do here, if other os-specific cases pop up in the future we can always reopen.
Activity
bijij commentedon Aug 12, 2020
Attempting to parse specific keys in zoneinfo.ZoneInfo with tzdata installed will raise unhandled exceptions
e.g. on windows
This happens when non TZif files or directories in the tzdata.zoneinfo module are used as keys.
vstinner commentedon Aug 12, 2020
Hi. It seems like you are running Windows.
About the permission error, how did you install tzdata? Did you install it as an admin user and do you run Python as a different user?
bijij commentedon Aug 12, 2020
tzdata was installed as an admin user, however this behaviour was
reproducible on a linux installation where for the ZoneInfo.('Pacific')
instance an IsADirectoryError would instead be raised.
On Wed, Aug 12, 2020 at 9:50 PM STINNER Victor <report@bugs.python.org>
wrote:
vstinner commentedon Aug 12, 2020
Oh right, 'Pacific' is a directory, not a valid zone, and so ZoneInfoNotFoundError should be raised. I see.
Example:
[-]Unhandled exceptions in zoneinfo.ZoneInfo constructor[/-][+]zoneinfo: ZoneInfo raises IsADirectoryError instead of ZoneInfoNotFoundError[/+][-]Unhandled exceptions in zoneinfo.ZoneInfo constructor[/-][+]zoneinfo: ZoneInfo raises IsADirectoryError instead of ZoneInfoNotFoundError[/+]vstinner commentedon Aug 12, 2020
On Linux, converting IsADirectoryError to ZoneInfoNotFoundError is easy.
But on Windows, I don't think that converting any PermissionError into a ZoneInfoNotFoundError is a good idea. Maybe if PermissionError happens, we should check if the path is a directory.
Pseudo-code:
try:
<open and read file>
except OSError as exc:
if os.path.isdir(zone_path):
raise ZoneInfoNotFoundError
else:
raise
23 remaining items
gh-85702: Catch PermissionError in zoneinfo.load_tzdata() (#136117)
pythongh-85702: Catch PermissionError in zoneinfo.load_tzdata() (pyth…
pythongh-85702: Catch IsADirectoryError in zoneinfo (pythonGH-131333)
[3.14] gh-85702: Catch PermissionError in zoneinfo.load_tzdata() (GH-…
[3.13] gh-85702: Catch IsADirectoryError in zoneinfo (GH-131333) (#13…
pythongh-85702: Catch PermissionError in zoneinfo.load_tzdata() (pyth…
[3.13] gh-85702: Catch PermissionError in zoneinfo.load_tzdata() (GH-…
StanFromIreland commentedon Jul 7, 2025
Windows pr and backports have been merged. I do not know of anything else to do here, if other os-specific cases pop up in the future we can always reopen.
pythongh-85702: Catch PermissionError in zoneinfo.load_tzdata() (pyth…
pythongh-85702: Catch PermissionError in zoneinfo.load_tzdata() (pyth…
pythongh-85702: Catch PermissionError in zoneinfo.load_tzdata() (pyth…
pythongh-85702: Catch PermissionError in zoneinfo.load_tzdata() (pyth…
pythongh-85702: Catch PermissionError in zoneinfo.load_tzdata() (pyth…