Re: Puzzling error msg.

Discussion in 'Python' started by Chris Angelico, Dec 3, 2012.

  1. On Tue, Dec 4, 2012 at 4:37 AM, <> wrote:
    > Traceback (most recent call last):
    > File "./Connection_Monitor.py", line 146, in <module>
    > Google_up, Google_summary, Google_RTT, Google_stddev = Google.connection_test()
    > File "/Users/wrw/Dev/Python/Connection_Monitor/Version2.2/WorkingCopy/network.py", line 101, in connection_test
    > #
    > IndexError: list index out of range
    >
    >
    > The routine is pasted in below:
    >
    > def connection_test(self):
    > self.network_up = True
    > self.error = None
    > ping_result = subprocess.Popen(['ping', '-qc6', self.target_IP], stderr = subprocess.PIPE, stdout = subprocess.PIPE).communicate()[0]
    > found_0 = '0 packets received' in ping_result
    > found_1 = '1 packets received' in ping_result
    > if found_0 == True or found_1 == True:
    > self.network_up = False
    > self.ping_summary = 'No route to host'
    > self.ping_RTT = 'NA'
    > self.ping_stddev = 'NA'
    > return self.network_up, self.ping_summary, self.ping_RTT, self.ping_stddev
    > #


    Is that the end of the function? What does it return if neither
    found_0 nor found_1? If that's the end, the function will be returning
    None (as all functions do on "flowing off the end"), but that would
    give a quite different error (namely, 'NoneType' is not iterable, at
    the unpacking).

    Is it possible that the error actually came from further up (with a
    faulty line number) and was actually because communicate() somehow
    returned an empty list? That's the only place in the code quoted that
    I'm seeing indexing, but communicate() is supposed to return a tuple,
    not a list.

    ChrisA
    Chris Angelico, Dec 3, 2012
    #1
    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. Steven D'Aprano

    Re: Puzzling error msg.

    Steven D'Aprano, Dec 3, 2012, in forum: Python
    Replies:
    0
    Views:
    162
    Steven D'Aprano
    Dec 3, 2012
  2. Ian Kelly

    Re: Puzzling error msg.

    Ian Kelly, Dec 3, 2012, in forum: Python
    Replies:
    0
    Views:
    195
    Ian Kelly
    Dec 3, 2012
  3. Dave Angel

    Re: Puzzling error msg.

    Dave Angel, Dec 4, 2012, in forum: Python
    Replies:
    0
    Views:
    146
    Dave Angel
    Dec 4, 2012
  4. Chris Angelico

    Re: Puzzling error msg.

    Chris Angelico, Dec 4, 2012, in forum: Python
    Replies:
    0
    Views:
    153
    Chris Angelico
    Dec 4, 2012
  5. Dave Angel

    Re: Puzzling error msg.

    Dave Angel, Dec 4, 2012, in forum: Python
    Replies:
    0
    Views:
    155
    Dave Angel
    Dec 4, 2012
Loading...

Share This Page