Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnknownTimeZoneError: '/UTC' #101

Closed
movermeyer opened this issue Oct 11, 2020 · 5 comments
Closed

UnknownTimeZoneError: '/UTC' #101

movermeyer opened this issue Oct 11, 2020 · 5 comments

Comments

@movermeyer
Copy link

movermeyer commented Oct 11, 2020

On the ubuntu Docker image, the contents of /etc/timezone is /UTC, which causes tzlocal to raise:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/tzlocal/unix.py", line 165, in get_localzone
    _cache_tz = _get_localzone()
  File "/usr/local/lib/python3.9/dist-packages/tzlocal/unix.py", line 86, in _get_localzone
    tz = pytz.timezone(etctz.replace(' ', '_'))
  File "/usr/local/lib/python3.9/dist-packages/pytz/__init__.py", line 181, in timezone
    raise UnknownTimeZoneError(zone)
pytz.exceptions.UnknownTimeZoneError: '/UTC'
Dockerfile that reproduces the issue
FROM ubuntu

RUN apt-get update && \
    apt install -y software-properties-common && \
    add-apt-repository ppa:deadsnakes/ppa && \
    apt-get update

# Install Python 3
RUN apt install -y python python-dev && \
    apt install -y python3.9 python3.9-dev python3.9-venv

# Make Python3 the default `python`
RUN ln -s /usr/lib/python3.9/_sysconfigdata__linux_x86_64-linux-gnu.py  /usr/lib/python3.9/_sysconfigdata__x86_64-linux-gnu.py && \
    update-alternatives --install /usr/bin/python python /usr/bin/python3.9 10

# Install pip
RUN apt-get install -y git curl gcc build-essential && \
    curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py && \
    python get-pip.py

# Get tzlocal
RUN pip install tzlocal

# Trigger the bug
RUN python -c "from tzlocal import get_localzone; tz = get_localzone()"
@movermeyer
Copy link
Author

I reported this bug (?) upstream: https://bugs.launchpad.net/ubuntu/+source/tzdata/+bug/1899343

@regebro
Copy link
Owner

regebro commented Oct 18, 2021

Is this still an issue? Because if it is I might just release a version that explicitly strips that infornation, but it's pretty silly to hack around a bug in a docker image config. :-)

@movermeyer
Copy link
Author

movermeyer commented Oct 18, 2021

@regebro I can still reproduce the issue using the steps listed in the issue I made upstream :

FROM ubuntu

RUN apt-get update && \
    apt-get install -y tzdata
$ docker build --no-cache -t tztest .
$ docker run -it --rm=true tztest cat /etc/timezone
/UTC

@regebro
Copy link
Owner

regebro commented Oct 18, 2021

An interesting question is what /etc/timezone is before the install of tzdata? I suspect it's non-existent, but perhaps not? The package install does read it, and there could be something going wrong there if it exists but with unexpected data...

@regebro
Copy link
Owner

regebro commented Oct 19, 2021

I added a workaround in 4.0.1. Annoying since this is a trivial bug in the Ubuntu config, but I have no idea how to contribute, it's very confusing.

@regebro regebro closed this as completed Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants