[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

referer url

pavloutefkros@gmail.com

1/28/2008 4:39:00 PM

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.
4 Answers

Tim Chase

1/28/2008 4:56:00 PM

0

> 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


pavloutefkros@gmail.com

1/28/2008 5:07:00 PM

0

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!

Tim Chase

1/28/2008 5:39:00 PM

0

> 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




pavloutefkros@gmail.com

1/28/2008 6:10:00 PM

0

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