Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 655
Alec Hewitt Avatar asked Jan 07 '14 14:01

Alec Hewitt


People also ask

What does country code ZZ mean?

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

Which country code is an?

AN is the two-letter country abbreviation for Netherlands Antilles.


2 Answers

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

like image 186
Machine Tribe Avatar answered Sep 26 '22 04:09

Machine Tribe


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.

like image 22
Romin Avatar answered Sep 25 '22 04:09

Romin