subprocess - python curl execute command with parameter -
i need execute following command
curl -v -h 'x-auth-user: myaccount:me' -h 'x-auth-key: secretpassword' http://localhost:8080/auth/v1.0/
when run terminal works perfectly. , gives me result following
* connect() localhost port 8080 (#0) * trying ::1... * connection refused * trying 127.0.0.1... * connected localhost (127.0.0.1) port 8080 (#0) > /auth/v1.0/ http/1.1 > user-agent: curl/7.29.0 > host: localhost:8080 > accept: */* > x-auth-user: myaccount:me > x-auth-key: secretpassword > < http/1.1 200 ok < x-storage-url: http://localhost:8080/v1/auth_myaccount < x-auth-token: auth_tk8bf07349d36041339450f0b46a2adc39 < content-type: text/html; charset=utf-8 < x-storage-token: auth_tk8bf07349d36041339450f0b46a2adc39 < content-length: 0 < x-trans-id: tx99a9e2a129f34ab487ace-00553cb059 < date: sun, 26 apr 2015 09:31:05 gmt < * connection #0 host localhost left intact
but need run python. have used subprocess.call , subprocess.popen in following way
import subprocess subprocess.call(["curl", "-v -h 'x-auth-user: myaccount:me' -h 'x-auth-key: secretpassword' http://localhost:8080/auth/v1.0/"], shell=false)
but getting followin error
curl: option -v -h 'x-auth-user: myaccount:me' -h 'x-auth-key: secretpassword' http://localhost:8080/auth/v1.0/: unknown curl: try 'curl --help' or 'curl --manual' more information
using popen
result = subprocess.popen(["curl", "-v -h 'x-auth-user: myaccount:me' -h 'x-auth-key: secretpassword' http://localhost:8080/auth/v1.0/"]) print(result)
and getting error
curl: option -v -h 'x-auth-user: myaccount:me' -h 'x-auth-key: secretpassword' http://localhost:8080/auth/v1.0/: unknown curl: try 'curl --help' or 'curl --manual' more information <subprocess.popen object @ 0x7fd003d82cd0>
how fix this???
since call
needs pass array of command line arguments, can split command line , call this:
subprocess.call([ "curl", "-v", "-h", "x-auth-user: myaccount:me", "-h", "x-auth-key: secretpassword", "http://localhost:8080/auth/v1.0/" ], shell=false)
Comments
Post a Comment