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.

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().

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.