Referrer key missing form os.environ dictionary?

Νίκος nikos.gr33k at gmail.com
Wed Sep 25 11:16:39 EDT 2013


Στις 25/9/2013 6:04 μμ, ο/η Steven D'Aprano έγραψε:
> On Wed, 25 Sep 2013 14:26:23 +0000, John Gordon wrote:
>
>> You could try this:
>>
>>      try:
>>          referer = os.environ.get('HTTP_REFERER', 'UnknownRef')
>>      except KeyError:
>>          referer = None
>>      if not referer:
>>          referer = 'UnknownRef'
>
> The get method will not raise KeyError. If the key is missing,
> 'UnknownRef' will be returned instead.
>
> So when Nikos reports that os.environ.get('HTTP_REFERER', 'UnknownRef')
> "doesn't return anything", he is mistaken. It returns 'UnknownRef'.
>
>
Not actually Steven,

the referer key works well but it was the simlutaneous "host" issues 
that was giving me false understanding. now it works ok?

So you say if the key is missign the get method wotn return an error but 
the default string instead. That is nice to hear.

But answer me plz this:

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?





More information about the Python-list mailing list