Referrer key missing form os.environ dictionary?
Ned Batchelder
ned at nedbatchelder.com
Wed Sep 25 11:09:02 EDT 2013
On 9/25/13 10:26 AM, John Gordon wrote:
> You could try this:
>
> try:
> referer = os.environ.get('HTTP_REFERER', 'UnknownRef')
> except KeyError:
> referer = None
>
> if not referer:
> referer = 'UnknownRef'
There's no need for the "except KeyError" clause. dict.get never raises
KeyError, this code will assign 'UnknownRef' in the case the environment
variable is missing.
--Ned.
More information about the Python-list
mailing list