You can use subprocess with Popen and communicate to execute commands and retrieve the output.
def executeCommand(cmd, debug = False):
'''
Excecute a command and return the stdiout and errors.
cmd: list of the command. e.g.: ['ls', '-la']
'''
try:
cmd_data = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output,error = cmd_data.communicate()
if debug:
if (len(error)>1):
print 'Error:', error
if (len(output)>1):
print 'Output:', output
return output, error
except:
return 'Error in command:', cmd
Then, you put your command as
executeCommand(['curl', '-k', '-H', '"Authorization: Bearer xxxxxxxxxxxxxxxx"', '-H', '"hawkular-tenant: test"', '-X', 'GET', 'https://www.example.com/test', '|', 'python', '-m', 'json.tool'])
cURLto Pythonrequestsconversion service. curl.trillworks.com is though.curl, rather than just sending HTTP requests from inside Python?