tzlocal: Multiple conflicting time zone configurations
Running on Ubuntu 16.04 I’m getting this error with tzlocal >= 4.0.1
Python 3.8.3 (default, Sep 2 2020, 09:15:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from tzlocal import get_localzone
>>> get_localzone()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dispo/test_pytz/lib/python3.8/site-packages/tzlocal/unix.py", line 205, in get_localzone
_cache_tz = _get_localzone()
File "/home/dispo/test_pytz/lib/python3.8/site-packages/tzlocal/unix.py", line 167, in _get_localzone
tzname = _get_localzone_name(_root)
File "/home/dispo/test_pytz/lib/python3.8/site-packages/tzlocal/unix.py", line 146, in _get_localzone_name
raise utils.ZoneInfoNotFoundError(message)
tzlocal.utils.ZoneInfoNotFoundError: 'Multiple conflicting time zone configurations found:\n/etc/timezone: America/Denver\n/etc/sysconfig/clock: America/Denver\n/usr/share/zoneinfo/Navajo: Navajo\nFix the configuration, or set the time zone in a TZ environment variable.\n'```
cat /etc/timezone America/Denver
cat /etc/sysconfig/clock ZONE=“America/Denver” UTC=false ARC=false
I don't know why it's checking /usr/share/zoneinfo/Navajo?
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 18 (9 by maintainers)
OK, no new issues for a few days, I released this as 4.1.
@davejennings That great! The warnings are expected. Are you explicitly using pytz? If not you may want to modify your code to use the standard datetime way of dealing with timezones instead. It’s been updated to handle the cases that it could not handle earlier, so the pytz API isn’t needed any more.
IIRC (it’s a year since I did this, I may misremember) instead of
localize()you use thereplace()function on the datetime to make a naive datetime into a timezone aware one, and you no longer need to callnormalize()after converting to another timezone.https://pytz-deprecation-shim.readthedocs.io/en/latest/migration.html has more information on the differences. But there is no panic in doing this, I won’t drop the pytz shim for at least a year, probably longer since I’m lazy.
os.path.realpath() just returns the real path, any middle symlinks are hidden, so doing it that way will be tricky. But I think what I have is a good solution.
I have released 4.1b1, please test it.
another:
also Ubuntu 18.04
This is a strange suggestion, but if /etc/timezone matches the name of the first-level symlink of /etc/localtime, maybe it would be the “correct” answer to return that, rather than following the second link?
But yeah, it does seem like the links are backwards. Navajo, GB, and Israel, for example, appear in the https://data.iana.org/time-zones/code/backward file. Could it be that somehow the links were reversed? I think I’m out of my depth here; I got lost in the Makefile