python curl execute command with parameter

LynAs

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???

JuniorCompressor

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

python curl execute command with parameter

From Dev

Execute a bash command with parameter in Python

From Java

Execute curl command within a Python script

From Dev

Using a variable to execute a curl command

From Dev

How to execute curl command in Chef recipe?

From Dev

Java execute "time curl -s" command

From Dev

Execute Firefox command in Python

From Dev

How to execute command by python?

From Dev

execute sql command in python

From Dev

Convert curl command into python code

From Dev

Curl command with options in Python 3

From Dev

Converting Curl command line to python

From Dev

How to execute command in Python script?

From Dev

Execute a command on Remote Machine in Python

From Dev

python - execute command and get output

From Dev

python: execute the content(command) in the dictionary

From Dev

Execute cURLs command line in Python

From Dev

Unable to execute CURL command through java Runtime.getRuntime().exec()

From Dev

how to escape this curl command to be used by LUA os.execute?

From Dev

How to execute curl command generated by for loop in bash shell?

From Dev

Curl command to POST data flask with extra parameter - unconsumed column

From Dev

Pass parameter string in URL similar to -d CURL command

From Dev

Usage of string parameter in "execute shell command" section of Jenkins

From Dev

Execute SQL command with parameter using Devart EF Drivers for Oracle

From Dev

What is the python requests equivalent of the following curl command

From Dev

Transforming curl command into Python pycurl or requests

From Dev

python pycurl equivalent of curl -b get command

From Dev

python pycurl equivalent of curl -b get command

From Dev

Translate cURL headers command to python-requests

Related Related

  1. 1

    python curl execute command with parameter

  2. 2

    Execute a bash command with parameter in Python

  3. 3

    Execute curl command within a Python script

  4. 4

    Using a variable to execute a curl command

  5. 5

    How to execute curl command in Chef recipe?

  6. 6

    Java execute "time curl -s" command

  7. 7

    Execute Firefox command in Python

  8. 8

    How to execute command by python?

  9. 9

    execute sql command in python

  10. 10

    Convert curl command into python code

  11. 11

    Curl command with options in Python 3

  12. 12

    Converting Curl command line to python

  13. 13

    How to execute command in Python script?

  14. 14

    Execute a command on Remote Machine in Python

  15. 15

    python - execute command and get output

  16. 16

    python: execute the content(command) in the dictionary

  17. 17

    Execute cURLs command line in Python

  18. 18

    Unable to execute CURL command through java Runtime.getRuntime().exec()

  19. 19

    how to escape this curl command to be used by LUA os.execute?

  20. 20

    How to execute curl command generated by for loop in bash shell?

  21. 21

    Curl command to POST data flask with extra parameter - unconsumed column

  22. 22

    Pass parameter string in URL similar to -d CURL command

  23. 23

    Usage of string parameter in "execute shell command" section of Jenkins

  24. 24

    Execute SQL command with parameter using Devart EF Drivers for Oracle

  25. 25

    What is the python requests equivalent of the following curl command

  26. 26

    Transforming curl command into Python pycurl or requests

  27. 27

    python pycurl equivalent of curl -b get command

  28. 28

    python pycurl equivalent of curl -b get command

  29. 29

    Translate cURL headers command to python-requests

HotTag

Archive