[Tutor] How can a CGI program get the URL that called it?

Danny Yoo dyoo at hashcollision.org
Fri Jan 10 23:10:31 CET 2014


On Thu, Jan 9, 2014 at 2:30 PM, Terry Carroll <carroll at tjc.com> wrote:
> How can my Python 2.7 CGI program find the URL that caused the program to be
> called?

Hi Terry,

According to the description of CGI:

    http://en.wikipedia.org/wiki/Common_Gateway_Interface

there should be a set of environmental variables that your program can
observe to reconstruct that portion of the request string.

In particular, you should be seeing SERVER_NAME, SERVER_PORT, and
other environmental variables if CGIHTTPServer from the Python
standard library is implementing the CGI protocol.

Checking...

    http://hg.python.org/cpython/file/0e5df5b62488/Lib/CGIHTTPServer.py#l157

Yes, you should be seeing SERVER_NAME and SERVER_PORT, unless
something strange is happening.


More information about the Tutor mailing list