GAE self.request.environ and server host
I'm trying to obtain the base URL (hostname) of the server in which my appengine app is running on.
Ie something along the lines of
wsgiref.util.application_uri(self.request.environ)
However it's returning the PATH_INFO which I do not want. Perhaps I'm missing something but even this article states the path info should be omitted. http://docs.python.org/library/wsgiref.html
http://9.latest.my-app.appspot.com
is basically along the lines of what i'm trying to r开发者_如何转开发etrieve. Instead it's returning
http://9.latest.my-app.appspot.com/my/requested/path
The request object is a Webob request object. As such, you can get the hostname from self.request.host
, the hostname with protocol from self.request.host_url
, and so forth.
You can find the hostname in os.environ['HTTP_HOST']
.
That won't include the protocol, but it should be easy to parse from the value you've got:
base = '/'.join(url.split('/')[:3])
or...
import urlparse
url = urlparse.urlparse(url)
base = "%s://%s" % (url.scheme, url.hostname)
精彩评论