Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   Re: Puzzling error msg. (http://www.velocityreviews.com/forums/t955078-re-puzzling-error-msg.html)

Chris Angelico 12-03-2012 08:33 PM

Re: Puzzling error msg.
 
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


All times are GMT. The time now is 01:40 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.