Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #34189

Re: Puzzling error msg.

References <C9E5F78F-CCC7-42B8-9A6F-4C4EA8C323E1@mac.com>
Date 2012-12-04 07:33 +1100
Subject Re: Puzzling error msg.
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.440.1354566815.29569.python-list@python.org> (permalink)

Show all headers | View raw


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

ChrisA

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Puzzling error msg. Chris Angelico <rosuav@gmail.com> - 2012-12-04 07:33 +1100

csiph-web