regebro / tzlocal

A Python module that tries to figure out what your local timezone is
MIT License
184 stars 58 forks source link

get_localzone() from tzlocal returns empty string #52

Closed syracine closed 6 years ago

syracine commented 6 years ago

Hello,

I'm completely new in Python. I installed a Python backup software from pip on Debian 8 server running Python 2.7.9. When I type the following command in shell, I get the following exception: `Python 2.7.9 (default, Jun 29 2016, 13:08:31) [GCC 4.9.2] on linux2 Type "help", "copyright", "credits" or "license" for more information.

from tzlocal import get_localzone tz=get_localzone() Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/tzlocal/unix.py", line 131, in get_localzone _cache_tz = _get_localzone() File "/usr/local/lib/python2.7/dist-packages/tzlocal/unix.py", line 70, in _getlocalzone return pytz.timezone(etctz.replace(' ', '')) File "/usr/local/lib/python2.7/dist-packages/pytz/init.py", line 191, in timezone raise UnknownTimeZoneError(zone) pytz.exceptions.UnknownTimeZoneError: ''`

My server is located in Quebec, Canada. I never used Python 2 or 3 before on this server. I installed this morning both Python 2 and 3 in parallel. I installed pytz and tzlocal from pip. Do I miss something or is it a bug? I tried it with pytz 2017.3 and tzlocal 1.4. I upgraded to 1.5.1 and the bug appeared again.

Regards

Sylvain Racine

regebro commented 6 years ago

You probably have an /etc/timezone or a /var/db/zoneinfo file, but it is empty. It should contain the timezone name, like America/Toronto or something like that.

syracine commented 6 years ago

That is exactly what I need to know: how to set local timezone. Work fine now!

Thank!