[Fix] zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key

The Error “zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key Asia/Hanoi'”, is an error that is invoked when you are working on a Django 4 Docker container and are trying to use a webservice.

Given below is the snippet of the error you might get:

zoneinfo._common.ZoneInfoNotFoundError: 'No time zone found with key Asia/Hanoi'

I would like to share with you the steps I took to fix the “zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key Asia/Hanoi'”

Why “zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key” Error is Seen?

The error, “zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key Asia/Hanoi'” is seen because the new version of pytz which you may be using in your project is buggy which is causing the error.

The pytz version 2022.2 is the version which is causing the error, you can try downgrading your version to version 2022.1.

There is also a short fix which you could do which could bypass this problem and fix the issue temporarily.

The detailed solution to fix the error “zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key Asia/Hanoi'”, is given below:

How to fix “zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key'” Error?

To fix the error “zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key Asia/Hanoi'” you can try downgrading your pytz version to version 2022.1, because version 2022.2 is know to cause this kinds of errors.

There is also a short fix which you could do which could bypass this problem and fix the issue temporarily. To do this short fix you will have to add some lines of code to your dockerfile.

To fix the error, “zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key Asia/Hanoi”, you will have to follow the steps mentioned below:

First, you will have to try downgrading your pytz version to version 2022.1, because version 2022.2 is know to cause this kinds of errors.

The new version of pytz which you may be using in your project is buggy which is causing the error.

If you are still facing the same error there is also a short fix which you could do which could bypass this problem and fix the issue temporarily.

To do this short fix you will have to add the below mentioned lines of code 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

This should fix the error “zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key Asia/Hanoi'”.

Conclusion

To fix the error “zoneinfo._common.ZoneInfoNotFoundError: ‘No time zone found with key Asia/Hanoi'” you can try downgrading your pytz version to version 2022.1, because version 2022.2 is know to cause this kinds of errors.

There is also a short fix which you could do which could bypass this problem and fix the issue temporarily. To do this short fix you will have to add some lines of code to your dockerfile.