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?

Tordek
  • 10,628
  • 3
  • 36
  • 67
karthik
  • 29
  • 2
  • 4
  • Shelling out to `curl` instead of using a library like `requests` could be considered the problem. – chepner Aug 16 '15 at 18:22

1 Answers1

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

Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321