Referrer key missing form os.environ dictionary?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Sep 25 11:04:46 EDT 2013
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'.
--
Steven
More information about the Python-list
mailing list