After rebuild of my Django 4 Docker container the web service stopped working with this error:
zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Asia/Hanoi'
My setup is:
- Python 3.10
- Django 4.0.5
Error:
web_1
Traceback (most recent call last): web_1
File "/usr/local/lib/python3.10/zoneinfo/_common.py", line 12, in load_tzdata web_1
return importlib.resources.open_binary(package_name, resource_name) web_1
File "/usr/local/lib/python3.10/importlib/resources.py", line 46, in open_binary web_1
return reader.open_resource(resource) web_1
File "/usr/local/lib/python3.10/importlib/abc.py", line 433, in open_resource web_1
return self.files().joinpath(resource).open('rb') web_1
File "/usr/local/lib/python3.10/pathlib.py", line 1119, in open web_1
return self._accessor.open(self, mode, buffering, encoding, errors, web_1
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.10/site-packages/tzdata/zoneinfo/Asia/Hanoi' web_1
web_1
During handling of the above exception, another exception occurred: web_1
web_1
Traceback (most recent call last): web_1
File "/home/app/web/manage.py", line 22, in <module> web_1
main() web_1
File "/home/app/web/manage.py", line 18, in main web_1
execute_from_command_line(sys.argv) web_1
File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 446, in execute_from_command_line web_1
utility.execute() web_1
File "/usr/local/lib/python3.10/site-packages/django/core/management/__init__.py", line 420, in execute web_1
django.setup() web_1
File "/usr/local/lib/python3.10/site-packages/django/__init__.py", line 24, in setup web_1
apps.populate(settings.INSTALLED_APPS) web_1
File "/usr/local/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate web_1
app_config.import_models() web_1
File "/usr/local/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models web_1
self.models_module = import_module(models_module_name) web_1
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module web_1
return _bootstrap._gcd_import(name[level:], package, level) web_1
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import web_1
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load web_1
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked web_1
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked web_1
File "<frozen importlib._bootstrap_external>", line 883, in exec_module web_1
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed web_1
File "/usr/local/lib/python3.10/site-packages/django_celery_beat/models.py", line 8, in <module> web_1
import timezone_field web_1
File "/usr/local/lib/python3.10/site-packages/timezone_field/__init__.py", line 1, in <module> web_1
from timezone_field.fields import TimeZoneField web_1
File "/usr/local/lib/python3.10/site-packages/timezone_field/fields.py", line 11, in <module> web_1
class TimeZoneField(models.Field): web_1
File "/usr/local/lib/python3.10/site-packages/timezone_field/fields.py", line 41, in TimeZoneField web_1
default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones] web_1
File "/usr/local/lib/python3.10/site-packages/timezone_field/fields.py", line 41, in <listcomp> web_1
default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones] web_1
File "/usr/local/lib/python3.10/zoneinfo/_common.py", line 24, in load_tzdata web_1
raise ZoneInfoNotFoundError(f"No time zone found with key {key}") web_1
zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Asia/Hanoi' web_1
[2022-08-12 09:18:36 +0000] [1] [INFO] Starting gunicorn 20.0.4 web_1
[2022-08-12 09:18:36 +0000] [1] [INFO] Listening at: http://0.0.0.0:8000 (1) web_1
[2022-08-12 09:18:36 +0000] [1] [INFO] Using worker: sync web_1
[2022-08-12 09:18:36 +0000] [11] [INFO] Booting worker with pid: 11 web_1
[2022-08-12 12:18:37 +0300] [11] [ERROR] Exception in worker process web_1
Traceback (most recent call last): web_1
File "/usr/local/lib/python3.10/zoneinfo/_common.py", line 12, in load_tzdata web_1
return importlib.resources.open_binary(package_name, resource_name) web_1
File "/usr/local/lib/python3.10/importlib/resources.py", line 46, in open_binary web_1
return reader.open_resource(resource) web_1
File "/usr/local/lib/python3.10/importlib/abc.py", line 433, in open_resource web_1
return self.files().joinpath(resource).open('rb') web_1
File "/usr/local/lib/python3.10/pathlib.py", line 1119, in open web_1
return self._accessor.open(self, mode, buffering, encoding, errors, web_1
FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.10/site-packages/tzdata/zoneinfo/Asia/Hanoi' web_1
web_1
During handling of the above exception, another exception occurred: web_1
web_1
Traceback (most recent call last): web_1
File "/usr/local/lib/python3.10/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker web_1
worker.init_process() web_1
File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/base.py", line 119, in init_process web_1
self.load_wsgi() web_1
File "/usr/local/lib/python3.10/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi web_1
self.wsgi = self.app.wsgi() web_1
File "/usr/local/lib/python3.10/site-packages/gunicorn/app/base.py", line 67, in wsgi web_1
self.callable = self.load() web_1
File "/usr/local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 49, in load web_1
return self.load_wsgiapp() web_1
File "/usr/local/lib/python3.10/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp web_1
return util.import_app(self.app_uri) web_1
File "/usr/local/lib/python3.10/site-packages/gunicorn/util.py", line 358, in import_app web_1
mod = importlib.import_module(module) web_1
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module web_1
return _bootstrap._gcd_import(name[level:], package, level) web_1
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import web_1
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load web_1
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked web_1
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked web_1
File "<frozen importlib._bootstrap_external>", line 883, in exec_module web_1
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed web_1
File "/home/app/web/config/wsgi.py", line 16, in <module> web_1
application = get_wsgi_application() web_1
File "/usr/local/lib/python3.10/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application web_1
django.setup(set_prefix=False) web_1
File "/usr/local/lib/python3.10/site-packages/django/__init__.py", line 24, in setup web_1
apps.populate(settings.INSTALLED_APPS) web_1
File "/usr/local/lib/python3.10/site-packages/django/apps/registry.py", line 116, in populate web_1
app_config.import_models() web_1
File "/usr/local/lib/python3.10/site-packages/django/apps/config.py", line 304, in import_models web_1
self.models_module = import_module(models_module_name) web_1
File "/usr/local/lib/python3.10/importlib/__init__.py", line 126, in import_module web_1
return _bootstrap._gcd_import(name[level:], package, level) web_1
File "<frozen importlib._bootstrap>", line 1050, in _gcd_import web_1
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load web_1
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked web_1
File "<frozen importlib._bootstrap>", line 688, in _load_unlocked web_1
File "<frozen importlib._bootstrap_external>", line 883, in exec_module web_1
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed web_1
File "/usr/local/lib/python3.10/site-packages/django_celery_beat/models.py", line 8, in <module> web_1
import timezone_field web_1
File "/usr/local/lib/python3.10/site-packages/timezone_field/__init__.py", line 1, in <module> web_1
from timezone_field.fields import TimeZoneField web_1
File "/usr/local/lib/python3.10/site-packages/timezone_field/fields.py", line 11, in <module> web_1
class TimeZoneField(models.Field): web_1
File "/usr/local/lib/python3.10/site-packages/timezone_field/fields.py", line 41, in TimeZoneField web_1
default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones] web_1
File "/usr/local/lib/python3.10/site-packages/timezone_field/fields.py", line 41, in <listcomp> web_1
default_zoneinfo_tzs = [ZoneInfo(tz) for tz in pytz.common_timezones] web_1
File "/usr/local/lib/python3.10/zoneinfo/_common.py", line 24, in load_tzdata web_1
raise ZoneInfoNotFoundError(f"No time zone found with key {key}") web_1
zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Asia/Hanoi' web_1
[2022-08-12 12:18:37 +0300] [11] [INFO] Worker exiting (pid: 11) web_1
[2022-08-12 09:18:37 +0000] [1] [INFO] Shutting down: Master web_1
[2022-08-12 09:18:37 +0000] [1] [INFO] Reason: Worker failed to boot.
In the Django settings file:
TIME_ZONE = 'UTC'
USE_TZ = True
PS: As suggested in another post I added tzdata
to my requirements file but nothing changed.
5条答案
按热度按时间iyzzxitl1#
将pytz版本从2022.2降级到2022.1似乎为我解决了这个问题。
qgzx9mmu2#
我也遇到了同样的错误。它帮助我解决了这个问题:
升级pytz和tzdata之后,我的Django项目又可以正常工作了!
zxlwwiss3#
作为一个快速(和肮脏)的方式来解决这个问题,添加以下行到您的Dockerfile:
piztneat4#
谢谢https://stackoverflow.com/a/73365642/1099058,它解决了我的问题。
1.使tzdata和pytz包为最新版本:
dly7yett5#
旧的和不正确的名称
Kiev
被重命名为正确的Kyiv
。在这种情况下,不是所有的包都被更新了,还有一些冲突。它将在一段时间内修复,但现在你可以使用符号链接来支持两个版本,只需在Linux中运行一个命令