[Tutor] 2.7.3 'CalledProcessError' error....why?

Emile van Sebille emile at fenx.com
Sat Aug 25 01:14:47 CEST 2012


On 8/24/2012 3:36 PM Ray Jones said...
> My code:
>
>    try:
>      subprocess.check_call(['ping', '-w1', ip])
>    except CalledProcessError:
>      print 'System', ip, 'is not responding. Exiting....'
>      sys.exit(4)
>    else: return None
>
> The result:
>
> Traceback (most recent call last):
>    File "./testing.py", line 222, in <module>
>      main()
>    File "./testing.py", line 170, in main
>      ip, port, endTime = parse_command_line(args)
>    File "./testing.py", line 111, in parse_command_line
>      ip = do_ip(args)
>    File "./testing.py", line 85, in do_ip
>      ping_ip(ip)
>    File "./testing.py", line 44, in ping_ip
>      except CalledProcessError:

Try it as:

         except subprocess.CalledProcessError, e
             print e.output



HTH,

Emile


> NameError: global name 'CalledProcessError' is not defined
>
> I didn't think Python return errors needed to be defined. I'll work
> around it with call_output, but what the heck is going on here? What do
> I not understand?
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>




More information about the Tutor mailing list