I am new to Python. I am trying to convert below bash script command to Python using subprocess. I don't get any output nor do I see any failure when I execute my Python script.
This is the bash command that needs to be ported to Python.
curl -u 'lawn:oldlawn!' -k -s -H 'Content-Type: application/json' -X GET 'https://192.168.135.20:443/api/json/v2/types/dev-objs/1'
My python code:
get_curl():
curl = """curl -u 'lawn:oldlawn!' -k -s -H 'Content-Type: application/json' -X GET 'https://192.168.135.20:443/api/json/v2/types/dev-objs/1'"""
args = curl.split()
process = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
print stdout
print stderr
# End of python code
After I execute get_curl(), print stdout and print stderr does not print anything though dev-objs/1 exists.
When I execute the same command as bash command it works and I see the REST API output.
Can anyone help me what may be going wrong here? Thanks
curlinstead of usingurllib?curl(and instead ofurllibtoo).urllibis built in?