Search code examples
pythongoogle-app-enginetimezonepytz

installing pytz in gae is giving UnknownTimeZoneError


unutbu answered my previous question nicely here 2, but there does not appear to be a pytz to import directly using my SDK. So I went looking for alternatives and found, for example this answer which recommends downloading from here 4.

I placed the following code in my local interactive console.

import datetime as dt
import pytz

utc = pytz.utc
western = pytz.timezone('US/Pacific')

I put the downloaded directory pytz in my local root directory scheduler and I unzipped the included file scheduler/pytz/zoneinfo.zip and got the following error in the interactive console. I did NOT adjust app.yaml at all; is that correct?

"/Users/brian/googleapps/scheduler/pytz/__init__.py", line 173, in timezone
    raise UnknownTimeZoneError(zone)
UnknownTimeZoneError: 'US/Pacific'

I also found an answer to a similar error here 5 which recommends a patch to the init.py file.

Now I have found an answer here 6 which suggests that errors occur if VERSION 2010h is used instead of VERSION 2011h and the pytz I downloaded is 2010h. What is UP?

Is there an easy way to be able to use Wooble's answer with pytz. And does his answer imply I have to upload the pytz directory with my gae app when it is deployed or is there a pytz alread there?


Solution

  • You need to call from pytz.gae import pytz in order that gae-pytz will work, otherwise you will be using the regular pytz.