So far in my experience with Python, it's error messages have been clear, concise, and quite good at fingering my errors. However, the message below has me stumped. The routine in question has been running for weeks with no problems, then yesterday I got the following:
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 # That particular command line generates 6 ping packets in quiet mode (summary only) and the amount of text returned, even when the ping fails is minimal. My puzzle two-fold. First: how could that code generate an "index our of range" error, and second: line 101 (the one fingered by the error message) is the line following the return statement, the one that contains the # character. I've seen that sort of line slippage when I forgot a ":", but that doesn't seem to be the case here. Python 2.7.3 from Python.org, running on Mac OS-X 10.8.2. For what it is worth, the definitions of the rest of the class variables follow (pretty simple minded): def __init__(self, target_name): lan_status = '' wan_status = '' path_status = '' ping_summary = '' ping_RTT = '' ping_stddev = '' target_error = '' network_up = True target_error, initial_route, hop_count, target_IP = find_initial_route(target_name) self.target_error = target_error self.initial_route = initial_route self.hop_count = hop_count self.gateway = initial_route[0] self.target_name = target_name self.target_IP = target_IP self.hop_count = hop_count self.lan_status = lan_status self.wan_status = wan_status self.path_status = path_status self.network_up = network_up self.ping_summary = ping_summary self.ping_RTT = ping_RTT self.ping_stddev = ping_stddev -- http://mail.python.org/mailman/listinfo/python-list