Puzzling error msg.

Chris Angelico rosuav at gmail.com
Mon Dec 3 21:33:31 CET 2012

On Tue, Dec 4, 2012 at 4:37 AM,  <wrw at mac.com> 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.


More information about the Python-list mailing list