1

I'm getting the error: function' object is unsubscriptable when using the subprocess module with curl command.

cmd (subprocess.check_call ['curl -X POST -u "opt:gggguywqydfydwfh" ' + Url + 'job/%s/%s/promotion/' % (job, Num)]).

I am calling this using the function.

def cmd(sh):
  proc = subprocess.Popen(sh, shell=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE).

Can anyone point out the problem?

1
  • Shelling out to curl instead of using a library like requests could be considered the problem. Commented Aug 16, 2015 at 18:22

1 Answer 1

4

You forgot the parens with check_call:

subprocess.check_call(["curl", "-X", "POST", "-u", "opt:gggguywqydfydwfh",Url + 'job/%s/%s/promotion/' % (job, Num)])

You are trying to subprocess.check_call[...

You are also passing it to your function, check_call returns the exit code so you are trying to pass 0 to your Popen call as sh which is going to fail.

If you actually want the output, forget the function and use check_output, you also need to pass a list of args:

out = subprocess.check_output(["curl", "-X", "POST", "-u", "opt:gggguywqydfydwfh", Url + 'job/%s/%s/promotion/' % (job, Num)])

Either way passing check_call to Popen is not the way to go

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

3 Comments

Also, you should specify the command arguments as separate list elements: ['curl', '-X', 'POST', ... ].
typo: subprocess.check_output
@augurar, yes, did not realise they weren't.

Your Answer

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.