Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Tuesday, December 8, 2015

More details on Google App Engine os.environ attributes

We can use python
os
package in Google App Engine to obtain some useful information for the request. As mentioned, we can obtain user geolocation of a user. Actually, there is a lot more we can do with it.

A LIVE DEMO is available. The demo contains a full list of
os.environ
keys and their corresponding values. Some values are not publicly disclosed, but you can try it in your own application.

The values are accessed with
os.environ[key]
with
key
value available, such as
HTTP_USER_AGENT
and
REMOTE_ADDR
. However, some of the App Engine-specific keys such as
USER_EMAIL
and
HTTP_X_APPENGINE_COUNTRY
, only exist in the GAE environment.

The following section comes with the complete source code.


Wednesday, September 9, 2015

How to obtain user geolocation with Google App Engine

Sometimes it is good to provide a better user experience by obtaining geolocation of a user. In Google App Engine, we can use the information in python
os
package to achieve this:

Get the current city of a user:

Get the current country of a user (Will return a ISO 3166-1 alpha-2 country code):

Note: If App Engine fails to supply a city name or country code, the output will be the second argument supplied to the
os.environ.get()
function call.

Update 13 Oct 2015: Added a Demo link

Update 7 Nov 2015: Added complete source code.