6

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

Mojtaba Rezaeian
  • 8,268
  • 8
  • 31
  • 54
Alec Hewitt
  • 805
  • 1
  • 12
  • 21

2 Answers2

13

'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.

Machine Tribe
  • 871
  • 9
  • 13
  • Thanks, do you know if you are ever likely to get ZZ in production? – Alec Hewitt Mar 03 '14 at 23:25
  • I would be prepared to at least catch those cases when you do. I have used other services like AdMob where the number of 'ZZ' cases is a lot higher than I would have expected. – Machine Tribe Mar 05 '14 at 14:23
  • I get "ZZ" and "unknown" in production. – F0r3v3r-A-N00b Nov 27 '14 at 00:17
  • 2
    "ZZ" was introduced in Unicode's cldr-data as a 'wildcard' for Country Codes when they appear elsewhere. For example if you want a default locale http://cldr.unicode.org in likelySubtags you will find values like "abt-Latn-ZZ" where ZZ means all countries for this language + scriptDesignator ... – sebilasse Apr 12 '17 at 10:37
4

I suggest that you use the correct case for the Request Header names. For e.g. X-AppEngine-Country

However, in the local development environment - I do not think the Location features will be supported i.e. you will not get the correct values. These should work only on the deployment environment. The Location is most likely provided by a Google Service that is internal to the Google Network and not exposed in the Local Development Environment.

Try to deploy your code to the live environment and check the values.

Romin
  • 8,708
  • 2
  • 24
  • 28