I need to execute the following command
curl -v -H 'X-Auth-User: myaccount:me' -H 'X-Auth-Key: secretpassword' http://localhost:8080/auth/v1.0/
when I run this from terminal it works perfectly. and gives me result like following
* About to connect() to localhost port 8080 (#0)
* Trying ::1...
* Connection refused
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET /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 to host localhost left intact
But i need to run this from python. I have used subprocess.call and subprocess.popen in the 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 I am getting the followin error
curl: option -v -H 'X-Auth-User: myaccount:me' -H 'X-Auth-Key: secretpassword' http://localhost:8080/auth/v1.0/: is unknown
curl: try 'curl --help' or 'curl --manual' for 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 for this
curl: option -v -H 'X-Auth-User: myaccount:me' -H 'X-Auth-Key: secretpassword' http://localhost:8080/auth/v1.0/: is unknown
curl: try 'curl --help' or 'curl --manual' for more information
<subprocess.Popen object at 0x7fd003d82cd0>
How to fix this???
Since call
needs to pass an array of command line arguments, you can split the command line yourself and call like this:
subprocess.call([
"curl", "-v", "-H", "X-Auth-User: myaccount:me", "-H",
"X-Auth-Key: secretpassword", "http://localhost:8080/auth/v1.0/"
], shell=False)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments