RE: KeyError

Discussion in 'Python' started by Doran_Dermot@emc.com, Dec 15, 2004.

  1. Guest

    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=
    [mailto:python-list-bounces+doran_dermot=] On Behalf Of

    Sent: 15 December 2004 13:34
    To:
    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
     
    , Dec 15, 2004
    #1
    1. Advertisements

  2. 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
     
    Roland Heiber, Dec 16, 2004
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Norman Shelley
    Replies:
    0
    Views:
    358
    Norman Shelley
    Oct 11, 2003
  2. Ajay
    Replies:
    5
    Views:
    724
    Uche Ogbuji
    Sep 12, 2004
  3. Guest

    KeyError

    Guest, Dec 15, 2004, in forum: Python
    Replies:
    1
    Views:
    1,984
    Diez B. Roggisch
    Dec 15, 2004
  4. Rune Strand

    Strange KeyError using cPickle

    Rune Strand, Jun 2, 2005, in forum: Python
    Replies:
    3
    Views:
    479
    Tim Peters
    Jun 2, 2005
  5. Replies:
    4
    Views:
    370
  6. nyenyec
    Replies:
    3
    Views:
    1,115
    Duncan Booth
    Jan 7, 2007
  7. Marc Girod

    KeyError: ... updated type, in planet

    Marc Girod, Aug 8, 2007, in forum: Python
    Replies:
    0
    Views:
    315
    Marc Girod
    Aug 8, 2007
  8. Adam W.

    Urllib keyerror, confused

    Adam W., Feb 2, 2008, in forum: Python
    Replies:
    1
    Views:
    699
    Navtej Singh
    Feb 2, 2008
Loading...