Referrer key missing form os.environ dictionary?

John Gordon gordon at panix.com
Wed Sep 25 10:26:23 EDT 2013


In <l1uqi7$qi5$1 at dont-email.me> =?UTF-8?B?zp3Or866zr/Pgg==?= <nikos.gr33k at gmail.com> writes:

> referer = os.environ.get('HTTP_REFERER', 'UnknownRef')

> but that doesn't return anything either.

When you say it "doesn't return anything", what exactly do you mean?  Does
it return None?  Does it raise KeyError?  Something else?

In any case, I'm surprised that doesn't work.  That should be the correct
way to do it.

You could try this:

    try:
        referer = os.environ.get('HTTP_REFERER', 'UnknownRef')
    except KeyError:
        referer = None

    if not referer:
        referer = 'UnknownRef'

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list