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 inner\r, 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 inner\r, 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_exception\r, 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_response\r, 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 error\r, 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 _log\r, 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 handle\r, 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 callHandlers\r, 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 handle\r, 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 emit\r, 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_text\r, 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 render\r, 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 _render\r, 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 render\r, 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_annotated\r, 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 render\r, 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 resolve\r, 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 date\r, 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_format\r, 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 format\r, 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_timezone\r, 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 timezone\r, referer: https://my_server_url
raise UnknownTimeZoneError(zone)\r, referer: https://my_server_url