referer url

Tim Chase python.list at
Mon Jan 28 17:55:38 CET 2008

> I was wondering, if there is a way to retrieve the referer url with
> python (web-based).
> I tried this:
> import os
> print os.getenv('HTTP_REFERER')
> but it's not working, even thought other http variables do function,
> this one is always a None.

This could be for any number of reasons, inter alia:

1) you don't specify the environment in which your python code is 
  running.  this may not get stashed in the os.getenv().  In 
Django, it's stashed in request.META.HTTP_REFERER; in CGI, it 
should be in your os.getenv(); in WebStack, the trans parameter 
has get_headers()/get_header_values() methods you can use to 
extract the referer; and in other frameworks, they may toss them 

2) the browser is configured to protect the privacy of the 
browser, and not send a Referer header

3) your server may not be configured to include the HTTP_REFERER 
environment variable (improbable, but possible)

4) your user(s) are coming from a book-marked link where there is 
no Referer to be sent


More information about the Python-list mailing list