I am getting 'ZZ' as country code when using pytz

Alec Hewitt picture Alec Hewitt · Jan 7, 2014 · Viewed 17.3k times · Source

I am using App engine, and I'm trying to get the time zone from the request. However when on local host it always seems to return 'ZZ' as the country code which is not a country in pytz library.

This code:

country = self.request.headers['X-Appengine-Country']
logging.info(country)
tz = pytz.country_timezones(country)

produces this error:

return self.data[key.upper()]
KeyError: 'ZZ'

many thanks for your help

Answer

Machine Tribe picture Machine Tribe · Mar 3, 2014

'ZZ' is often used to denote 'Unknown or unspecified country'

There is also a numeric version of the two letter code, calculated as 1070+30a+b, where a and b are the two letters of the code converted by A=1, B=2, etc. So AA=1101, AB=1102, BA=1131, and ZZ=1876.