Referrer key missing form os.environ dictionary?
Grant Edwards
invalid at invalid.invalid
Wed Sep 25 11:18:41 EDT 2013
On 2013-09-25, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> On Wed, 25 Sep 2013 17:04:55 +0300, ?????????? wrote:
>
>> I would like to check for its existence and retrieve it if possible, if
>> its not there then default to the string "UnKnown Ref".
>>
>> I try to do this with:
>>
>> referer = os.environ.get('HTTP_REFERER', 'UnknownRef')
>>
>> but that doesn't return anything either.
And of course that's bolloks:
Python 2.7.5 (default, Aug 29 2013, 15:13:35)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ.get('HTTP_REFERER','UnkownRef')
'UnkownRef'
>>>
Python 3.2.5 (default, Aug 29 2013, 15:19:46)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.environ.get('HTTP_REFERER','UnkownRef')
'UnkownRef'
>>>
>> Can you verify that its the correct way to grab the referral string?
It is.
> The Referer is not an environment variable.
It is when you're writing a CGI app.
> How would your shell know what URL you were just browsing?
Because the HTTP server sets those environment variables before
invoking the CGI app.
--
Grant Edwards grant.b.edwards Yow! Boy, am I glad it's
at only 1971...
gmail.com
More information about the Python-list
mailing list