skip to Main Content

I’ve deployed a Django Application on Windows Server 2022 and error logs are flooded with the following message:

pytz.exceptions.UnknownTimeZoneError: 'Europe/Paris'r, referer: https://my_server_url
During handling of the above exception, another exception occurred

I’ve checked my pytz installation and it seems to work just fine :

# run Windows cmd as Apache service account
python manage.py shell
from django.conf import settings
import pytz
pytz.timezone(settings.TIME_ZONE)
<DstTzInfo 'Europe/Paris' LMT+0:09:00 STD>
settings.TIME_ZONE in pytz.all_timezones
True

I’ve tried to uninstall and reinstall my virtual environnement and upgrade/downgrade pytz, without success.

I’ve no idea on how to investigate this problem furthermore and how to solve it.

Here is the application setup :

Apache 2.4.52 (built from sources)
Python 3.10.4
Mod_wsgi 4.9.0
Django 3.2.9
pytz 2021.3

Edit 1.

Here are the relevant Django settings (I mostly use defaults):

TIME_ZONE = 'Europe/Paris'
USE_TZ = False
USE_L10N = False # also tried with True, same error

Edit 2.

Here is the full error traceback.

 # when any exception is raised in the app
 During handling of the above exception, another exception occurred:r, referer: https://my_server_url
 r, referer: https://my_server_url
 Traceback (most recent call last):r, referer: https://my_server_url
   File "path_to_venv\django\core\handlers\exception.py", line 47, in innerr, referer: https://my_server_url
     response = get_response(request)r, referer: https://my_server_url
   File "path_to_venv\django\utils\deprecation.py", line 117, in __call__r, referer: https://my_server_url
     response = response or self.get_response(request)r, referer: https://my_server_url
   File "path_to_venv\django\core\handlers\exception.py", line 49, in innerr, referer: https://my_server_url
     response = response_for_exception(request, exc)r, referer: https://my_server_url
   File "path_to_venv\django\core\handlers\exception.py", line 115, in response_for_exceptionr, referer: https://my_server_url
     log_response(r, referer: https://my_server_url
   File "path_to_venv\django\utils\log.py", line 224, in log_responser, referer: https://my_server_url
     getattr(logger, level)(r, referer: https://my_server_url
   File "C:\Program Files\Python3.10\Lib\logging\__init__.py", line 1497, in errorr, referer: https://my_server_url
     self._log(ERROR, msg, args, **kwargs)r, referer: https://my_server_url
   File "C:\Program Files\Python3.10\Lib\logging\__init__.py", line 1615, in _logr, referer: https://my_server_url
     self.handle(record)r, referer: https://my_server_url
   File "C:\Program Files\Python3.10\Lib\logging\__init__.py", line 1625, in handler, referer: https://my_server_url
     self.callHandlers(record)r, referer: https://my_server_url
   File "C:\Program Files\Python3.10\Lib\logging\__init__.py", line 1687, in callHandlersr, referer: https://my_server_url
     hdlr.handle(record)r, referer: https://my_server_url
   File "C:\Program Files\Python3.10\Lib\logging\__init__.py", line 967, in handler, referer: https://my_server_url
     self.emit(record)r, referer: https://my_server_url
   File "path_to_venv\django\utils\log.py", line 120, in emitr, referer: https://my_server_url
     message = "%s\n\n%s" % (self.format(no_exc_record), reporter.get_traceback_text())r, referer: https://my_server_url
   File "path_to_venv\django\views\debug.py", line 353, in get_traceback_textr, referer: https://my_server_url
     return t.render(c)r, referer: https://my_server_url
   File "path_to_venv\django\template\base.py", line 170, in renderr, referer: https://my_server_url
     return self._render(context)r, referer: https://my_server_url
   File "path_to_venv\django\template\base.py", line 162, in _renderr, referer: https://my_server_url
     return self.nodelist.render(context)r, referer: https://my_server_url
   File "path_to_venv\django\template\base.py", line 938, in renderr, referer: https://my_server_url
     bit = node.render_annotated(context)r, referer: https://my_server_url
   File "path_to_venv\django\template\base.py", line 905, in render_annotatedr, referer: https://my_server_url
     return self.render(context)r, referer: https://my_server_url
   File "path_to_venv\django\template\base.py", line 988, in renderr, referer: https://my_server_url
     output = self.filter_expression.resolve(context)r, referer: https://my_server_url
   File "path_to_venv\django\template\base.py", line 698, in resolver, referer: https://my_server_url
     new_obj = func(obj, *arg_vals)r, referer: https://my_server_url
   File "path_to_venv\django\template\defaultfilters.py", line 717, in dater, referer: https://my_server_url
     return formats.date_format(value, arg)r, referer: https://my_server_url
   File "path_to_venv\django\utils\formats.py", line 152, in date_formatr, referer: https://my_server_url
     return dateformat.format(value, get_format(format or 'DATE_FORMAT', use_l10n=use_l10n))r, referer: https://my_server_url
   File "path_to_venv\django\utils\dateformat.py", line 326, in formatr, referer: https://my_server_url
     df = DateFormat(value)r, referer: https://my_server_url
   File "path_to_venv\django\utils\dateformat.py", line 59, in __init__r, referer: https://my_server_url
     self.timezone = get_default_timezone()r, referer: https://my_server_url
   File "path_to_venv\django\utils\timezone.py", line 52, in get_default_timezoner, referer: https://my_server_url
     return pytz.timezone(settings.TIME_ZONE)r, referer: https://my_server_url
   File "path_to_venv\pytz\__init__.py", line 188, in timezoner, referer: https://my_server_url
     raise UnknownTimeZoneError(zone)r, referer: https://my_server_url

2

Answers


  1. Django 4 disables time zones by default. According to this, you should set USE_TZ to True to enable it. Django 5 will enable it by default.
    See also USE_TZ for more info about this setting and links to related settings.

    Login or Signup to reply.
  2. You are using linux timezone format on Windows server. Here is mapping

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search