[Django]-ZoneInfoNotFoundError: 'No time zone found with key utc'

56👍

Add tzdata to your requirements or pip install tzdata

10👍

Instead of ‘UTC’ use ‘zone/city’, e.g. TIME_ZONE = 'Europe/Moscow'

A list of possible values ​​can be obtained like this:

import zoneinfo
zoneinfo.available_timezones()
👤Dr3d

4👍

This solved this problem

pip install pytz --upgrade
pip install tzdata --upgrade

0👍

I got the same error below:

zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key America/NewYork’

Because I set 'America/NewYork' to TIME_ZONE as shown below:

# "settings.py"

TIME_ZONE = 'America/NewYork'

So, I set 'America/New_York' to TIME_ZONE as shown below, then the error was solved:

# "settings.py"
                      # ↓ "_" is added
TIME_ZONE = 'America/New_York'

-1👍

my python’s version is 3.11 and Django’s version is 4.2.1

I got the same error before:

zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key UTC+8'

I tried other methods from this page, such as pip install tzdata or pip install pytz , but none of them worked .

finally, I changed the value of TIME_ZONE from ‘UTC+8’ to ‘Asia/ShangHai’, and then the error disappeared!

before:

#settings.py
TIME_ZONE = 'UTC+8'

after:

#settings.py
TIME_ZONE = 'Asia/ShangHai'
👤KLW

-3👍

for docker container:

docker exec -it your_docker_id bash
bash-5.1# pip install tzdata
👤Gata

Leave a comment