Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.021 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'else:': 0.03; 'subject:form': 0.07; 'subject:missing': 0.07; '-tkc': 0.16; 'brackets.': 0.16; 'doesnt': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'keyerror': 0.16; 'subject:key': 0.16; 'all.': 0.16; 'wrote:': 0.18; 'previously': 0.22; 'header': 0.24; 'environment': 0.24; 'header:In-Reply-To:1': 0.27; 'wondering': 0.29; 'thus': 0.29; "skip:' 10": 0.31; 'exceptions': 0.31; 'noted': 0.31; 'skip:d 20': 0.34; 'but': 0.35; 'subject:?': 0.36; 'skip:o 20': 0.38; 'work?': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:o 30': 0.61; 'browser': 0.61; 'now:': 0.74; 'square': 0.74; 'guaranteed': 0.75; 'received:50.22': 0.84; 'ref': 0.84; 'reasons,': 0.91 Date: Wed, 25 Sep 2013 10:14:50 -0500 From: Tim Chase To: python-list@python.org Subject: Re: Referrer key missing form os.environ dictionary? In-Reply-To: References: <5242f8bc$0$30000$c3e8da3$5496439d@news.astraweb.com> X-Mailer: Claws Mail 3.8.1 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - boston.accountservergroup.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tim.thechases.com X-Get-Message-Sender-Via: boston.accountservergroup.com: none X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1380121985 news.xs4all.nl 15961 [2001:888:2000:d::a6]:33719 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54745 On 2013-09-25 18:02, =CE=9D=CE=AF=CE=BA=CE=BF=CF=82 wrote: > This indeed works now: >=20 > ref =3D os.environ.get('HTTP_REFERER', '=CE=86=CE=B3=CE=BD=CF=89=CF=83=CF= =84=CE=BF Ref') >=20 > but iam wondering why this doesnt work also: >=20 > ref =3D os.environ('HTTP_REFERER') >=20 > Shouldnt both work? No...that calls os.environ. You likely *mean* ref =3D os.environ['HTTP_REFERER'] using square brackets. However, as previously noted by multiple respondents, this header is not guaranteed to be sent by the browser for a variety of reasons, so it may not be in the environment dictionary at all. Thus you are likely to get KeyError exceptions if you don't use .get() unless you wrap it in a check: if "HTTP_REFERER" in os.environ: ref =3D os.environ["HTTP_REFERER"] else: deal_with_this_situation() -tkc