Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

KeyError

97 views
Skip to first unread message

root...@gazeta.pl

unread,
Dec 15, 2004, 8:33:41 AM12/15/04
to pytho...@python.org
Hello.
Maybe someone will help me with this KeyError:

............................
Traceback (most recent call last):
File "C:\Python\tabla.py", line 929, in -toplevel-
tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
File "C:\Python23\lib\os.py", line 417, in __getitem__
return self.data[key.upper()]
KeyError: 'REMOTE_ADDR'
..........................


Thanks for reading this.
R.

Frans Englich

unread,
Dec 15, 2004, 8:49:20 AM12/15/04
to root...@gazeta.pl, pytho...@python.org

What trouble do you have? AFAICT, The key REMOVE_ADDR wasn't in the
dictionary, meaning that the environment variable doesn't exist.


Cheers,

Frans

Doran_...@emc.com

unread,
Dec 15, 2004, 8:43:57 AM12/15/04
to root...@gazeta.pl, pytho...@python.org
Hi "R",

The only explanation I can give is that the environment varialbe REMOTE_ADDR
does not exist! Wrap your high-level code with try and except. Example:
try:


tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']

except KeyError:
# Code to handle the fact tht REMOT_ADDR does not exist.

Hope that this helps and is not just another infamous "Dermot Didn't Get It"
posting!

Cheers!!

-----Original Message-----
From: python-list-bounces+doran_dermot=emc...@python.org
[mailto:python-list-bounces+doran_dermot=emc...@python.org] On Behalf Of
root...@gazeta.pl
Sent: 15 December 2004 13:34
To: pytho...@python.org
Subject: KeyError

Hello.
Maybe someone will help me with this KeyError:

............................
Traceback (most recent call last):
File "C:\Python\tabla.py", line 929, in -toplevel-
tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
File "C:\Python23\lib\os.py", line 417, in __getitem__
return self.data[key.upper()]
KeyError: 'REMOTE_ADDR'
..........................

Thanks for reading this.
R.

--
http://mail.python.org/mailman/listinfo/python-list

Diez B. Roggisch

unread,
Dec 15, 2004, 8:58:34 AM12/15/04
to
root...@gazeta.pl wrote:

That tabla.py of yours is certainly to be executed in a CGI environment. So
call it that way - or provide the neccessary environment by stuffing values
to os.environ


--
Regards,

Diez B. Roggisch

Roland Heiber

unread,
Dec 16, 2004, 5:27:57 AM12/16/04
to
Doran_...@emc.com wrote:
> Hi "R",
>
> The only explanation I can give is that the environment varialbe REMOTE_ADDR
> does not exist! Wrap your high-level code with try and except. Example:
> try:
> tablesDirectory = tablesDirectoryPrefix + os.environ['REMOTE_ADDR']
> except KeyError:
> # Code to handle the fact tht REMOT_ADDR does not exist.

... or just replace os.environ['REMOTE_ADDR'] with
os.environ.get('REMOTE_ADDR', 'enter_default_here') to use a default in
case of missing REMOTE_ADDR ...

HtH, Roland

Doran_...@emc.com

unread,
Dec 16, 2004, 6:10:03 AM12/16/04
to roland...@web.de, pytho...@python.org
If a default value would be acceptable to the application (which is quite
likely), then this would be a much cleaner solution.

-----Original Message-----
From: python-list-bounces+doran_dermot=emc...@python.org
[mailto:python-list-bounces+doran_dermot=emc...@python.org] On Behalf Of

HtH, Roland
--
http://mail.python.org/mailman/listinfo/python-list

0 new messages