0

I have the following issue:

 try:
 with subprocess.check_call(query):
 return 1
 except ValueError:
 return -1

This code runs a shell script and it's working so far. The script returns 0. Nevertheless I got this error:

with subprocess.check_call(query):
AttributeError: 'int' object has no attribute '__exit__'

so there has to be someting wrong with my try/except block.

asked Aug 16, 2013 at 7:26

1 Answer 1

4

subprocess.check_call() returns an int status code 0, not a context manager. You cannot use it in a with statement.

return subprocess.check_call(query)

Just return the return value of that call. Note that it will not raise a ValueError exception either; it'll raise CalledProcessError if the process exits with a non-zero status code.

Perhaps what you really wanted to use was subprocess.call().

answered Aug 16, 2013 at 7:31
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.