Referrer key missing form os.environ dictionary?

Tim Chase python.list at tim.thechases.com
Wed Sep 25 11:42:45 EDT 2013


On 2013-09-25 18:16, Νίκος wrote:
> how caom the http_referer thing works ok now but when i just print
> all the key listing of .os.environ ket the http_referer key isnt
> inside?

Well, first off, it's entirely possible (based on reading that
paragraph) that you typed something wrong.

That said, it depends on whether you're looking in your local
environment, or the CGI environment provided by the server.  As a
simple example of what the server-side has/puts in your environment,
you can use this CGI script:


#!/usr/bin/env python
import cgitb; cgitb.enable()
import cgi
import os
import sys
print "Content-Type: text/html\n\n"
print """
<html>
 <head>
  <title>Test CGI</title>
  <style>dt{font-weight: bold;}</style>
 </head>
 <body>
 <dl>"""
for k,v in sorted(os.environ.items()):
    print "<dt>%s</dt>" % cgi.escape(k)
    print "<dd>%s</dd>" % cgi.escape(v)
print """
 </dl>
 </body>
</html>"""

Note that, if you go directly to the page, you shouldn't have a
refer[r]er header, while if you arrive at it from some previous page,
you might (modulo the aforementioned chicanery that plugins can
induce)

-tkc










More information about the Python-list mailing list