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. Advertising

  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. Advertising

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:
    279
    Norman Shelley
    Oct 11, 2003
  2. Ajay
    Replies:
    5
    Views:
    585
    Uche Ogbuji
    Sep 12, 2004
  3. Guest

    KeyError

    Guest, Dec 15, 2004, in forum: Python
    Replies:
    1
    Views:
    1,879
    Diez B. Roggisch
    Dec 15, 2004
  4. Frans Englich

    Re: KeyError

    Frans Englich, Dec 15, 2004, in forum: Python
    Replies:
    0
    Views:
    360
    Frans Englich
    Dec 15, 2004
  5. RE: KeyError

    , Dec 16, 2004, in forum: Python
    Replies:
    0
    Views:
    424
Loading...

Share This Page