Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the Server URL in Google App Engine using python

How do I get App Engine to generate the URL of the server it is currently running on?

If the application is running on development server it should return

http://localhost:8080/

and if the application is running on Google's servers it should return

http://application-name.appspot.com
like image 373
Gautam Avatar asked Jun 16 '11 14:06

Gautam


People also ask

What is App Engine HTTP?

App Engine is a fully managed, serverless platform for developing and hosting web applications at scale. You can choose from several popular languages, libraries, and frameworks to develop your apps, and then let App Engine take care of provisioning servers and scaling your app instances based on demand.


2 Answers

You can get the URL that was used to make the current request from within your webapp handler via self.request.url or you could piece it together using the self.request.environ dict (which you can read about on the WebOb docs - request inherits from webob)

You can't "get the url for the server" itself, as many urls could be used to point to the same instance.

If your aim is really to just discover wether you are in development or production then use:

'Development' in os.environ['SERVER_SOFTWARE']
like image 151
Chris Farmiloe Avatar answered Oct 16 '22 06:10

Chris Farmiloe


Here is an alternative answer.

from google.appengine.api import app_identity
server_url = app_identity.get_default_version_hostname()

On the dev appserver this would show:

localhost:8080

and on appengine

your_app_id.appspot.com

like image 32
A_Porcupine Avatar answered Oct 16 '22 07:10

A_Porcupine