skip to Main Content

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

Answers


  1. Downgrading the pytz version from 2022.2 to 2022.1 seems to have solved this issue for me.

    Login or Signup to reply.
  2. As a quick (and dirty) way to fix this add these lines to your Dockerfile:

    RUN cp /usr/local/lib/python3.10/site-packages/tzdata/zoneinfo/Asia/Aden /usr/local/lib/python3.10/site-packages/tzdata/zoneinfo/Asia/Hanoi && 
    cp /usr/local/lib/python3.10/site-packages/tzdata/zoneinfo/Europe/Moscow /usr/local/lib/python3.10/site-packages/tzdata/zoneinfo/Europe/Kyiv
    
    Login or Signup to reply.
  3. I’ve got the same error. It helps me to fix it:

    # upgrade pytz up to the latest pytz-2022.2.1
    pip install pytz --upgrade
    # upgarde tzdata up to tzdata-2022.2
    pip install tzdata --upgrade
    

    After upgrades pytz and tzdata my Django project is working just fine again!

    Login or Signup to reply.
  4. thanks for https://stackoverflow.com/a/73365642/1099058, it’s solve my problem.

    1. make tzdata and pytz package to latest version:
       pip uninstall pytz
       pip install pytz==2022.2.1
       pip uninstall tzdata
       pip install tzdata==2022.2
    
    1. test django in 4.0.5 and 4.1 will working:
      my enviroments
    Login or Signup to reply.
  5. The old and incorrect name Kiev was renamed to correct Kyiv. In this case not all packages were updated and there are some conflicts. It will be fixed over time, but for now you can just use a symlink to support both version just running a command in your Linux

    ln -s /usr/share/zoneinfo/Europe/Kiev /usr/share/zoneinfo/Europe/Kyiv
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search