-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
ZoneInfo object raises OSError instead of ZoneInfoNotFoundError for timezone input larger than 255 characters #96463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I cannot reproduce it on macos. I've tried >>> from zoneinfo import ZoneInfo
>>> ZoneInfo("a"*256)
Traceback (most recent call last):
File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/zoneinfo/_common.py", line 12, in load_tzdata
return importlib.resources.open_binary(package_name, resource_name)
File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/importlib/resources.py", line 43, in open_binary
package = _common.get_package(package)
File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/importlib/_common.py", line 66, in get_package
resolved = resolve(package)
File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/importlib/_common.py", line 57, in resolve
return cand if isinstance(cand, types.ModuleType) else importlib.import_module(cand)
File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'tzdata'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/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 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' Trying |
Hi, I think the absence of I tried |
Thanks, now I can see this error. But, in the mean time: can you please explain how practical is it to catch this exception? There are too many use-cases for |
You are correct blindly catching |
Technically, since this data comes from the @pganssle do you have any thoughts regarding this? |
Here's another case where this happens: on Windows, there are a number of characters that are apparently not allowed in file names, and can generate OSErrors with errno=22 (EINVAL). On Windows: from zoneinfo import ZoneInfo
ZoneInfo("*") elicits an A string containing any of the characters "*", "<", ">", ":", '"', "?" or any of the control characters "\x01" through "\x1f" will work to elicit the EINVAL. There's repo with a small, trivial test here: https://github.com/dairiki/zoneinfo-bug/ |
255 bytes is the max filename length on certain OSs. There does not seem to be a defined maximum but from what I can tell 255 would defiantly cover all, maybe just limiting it to that would suffice. SO I can open a PR for this. |
Uh oh!
There was an error while loading. Please reload this page.
Bug report
According to documentation all calls to ZoneInfo should raise
ValueError
orZoneInfoNotFoundError
.Creating a ZoneInfo object with an invalid very long timezone (length > 255) an OSError is raised instead (
OSError: [Errno 36] File name too long
).I believe that
cpython/Lib/zoneinfo/_common.py
Lines 11 to 24 in 29f1b0b
OSError
exception raised by open and reraise it toZoneInfoNotFoundError
.Sample code for reproduction:
Your environment
Linked PRs
load_tzdata
raisingOSError
, not `ZoneInfoNotFound… #99602The text was updated successfully, but these errors were encountered: