tags:

views:

268

answers:

2

Hi, I couldn't find out python equivalent to PHP $_SERVER.

Is there any? Or, what are the methods to bring equivalent results?

Thanks in advance.

+7  A: 

Using mod_wsgi, which I would recommend over mod_python (long story but trust me) ... Your application is passed an environment variable such as:

def application(environ, start_response):
    ...

And the environment contains typical elements from $_SERVER in PHP

...
environ['REQUEST_URI'];
...

And so on.

http://www.modwsgi.org/

Good Luck

Aiden Bell
Thanks a lot. That will do :)
fireball003
+1  A: 

You don't state it explicitly, but I assume you are using mod_python? If so, (and if you don't want to use mod_wsgi instead as suggested earlier) take a look at the documentation for the request object. It contains most of the attributes you'd find in $_SERVER.
An example, to get the full URI of the request, you'd do this:

def yourHandler(req):
    querystring=req.parsed_uri[apache.URI_QUERY]

The querystring attribute will now contain the request's querystring, that is, the part after the '?'. (So, for http://www.example.com/index?this=test, querystring would be this=test)

carlpett