referer url

P

pavloutefkros

Hello all!

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.

Thanks in advance.
 
T

Tim Chase

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
elsewhere.

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

-tkc
 
P

pavloutefkros

Thanks for the reply.
1) CGI so i'm doing it right.
2) this is impossible as i'm doing the exact same thing with another
language and it utterly works.
3) the same as above
4) no..

this gets nerve breaking!
 
T

Tim Chase

1) CGI so i'm doing it right.

that's helpful to know
2) this is impossible as i'm doing the exact same thing with another
language and it utterly works.

Just making sure...same browser/setup/configuration, different
language?
3) the same as above

kinda figured...most servers give you the HTTP_REFERER, so you'
have to
4) no..

this gets nerve breaking!

Well, you can always dump the contents of os.environ into your
output to see if you can find why.

from cgi import escape
out.write('<br>'.join([
'<b>%s:</b>%s' % (escape(k), escape(v))
for k,v in os.environ.iteritems()
])

-tkc
 
P

pavloutefkros

Thanks for that! i found the variable in "ALL_HTTP" and it's working
now.
Thanks again..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top