execute curl command in python
<p>I have already gone through few StackOverflow existing links for this query, did not help me.</p>

<p>I would like to run few curl command(4) and each curl commands give output. From that output, I would like to parse the few group ids for next command.</p>

<pre><code>curl --basic -u admin:admin -d \'{ "name" : "test-dev" }\' --header \'Content-Type: application/json\' http://localhost:8080/mmc/api/serverGroups
</code></pre>

<p>I have tried with as ,</p>

<pre><code>#!/usr/bin/python

import subprocess
bash_com = 'curl --basic -u admin:admin -d '{ "name" : "test-dev" }' --header 'Content-Type: application/json' http://localhost:8080/mmc/api/serverGroups'
subprocess.Popen(bash_com)
output = subprocess.check_output(['bash','-c', bash_com]) # subprocess has check_output method
</code></pre>

<p>It gives me the syntax error, though I have changed from a single quote to double quote for that curl command.</p>

<p>I have been trying with Pycurl but i have to look more into that. Is there any way we can run curl commands in python and can parse the output values and pass it to next curl command.</p>

<p>Better output using os.open(bash_com,'r') and then fh.read()</p>

<h1>python api.py</h1>

<p>% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
199   172    0   172    0    27   3948    619 --:--:-- --:--:-- --:--:--  4027
<strong>{"href":"<a href="http://localhost:8080/mmc/api/serverGroups/39a28908-3fae-4903-adb5-06a3b7bb06d8" rel="nofollow">http://localhost:8080/mmc/api/serverGroups/39a28908-3fae-4903-adb5-06a3b7bb06d8</a>","serverCount":0,"name":"test-dev","id":"39a28908-3fae-4903-adb5-06a3b7bb06d8"}</strong></p>

<p>trying understand that fh.read() has executed the curl command? please correct me</p>

python curl esb