json - I get the output when i run the curl request in command line but not able to get the output when using python -


subprocess.call('curl https://api.smartsheet.com/1.1/sheets -h "authorization: bearer 26lhbngfsybdayabz6afrc6dcd" -h "content-type: application/json" -x post -d @test.json' )

my test.json has:

{      "name":"newsheet",    "columns":[         {            "title":"favorite",          "type":"checkbox",          "symbol":"star"       },       {            "title":"primary column",          "primary":true,          "type":"text_number"       },       {            "title":"status",          "type":"picklist",          "options":[               "not started",             "started",             "completed"          ]       }    ] } 

try this:

from subprocess import pipe, popen  p = popen('curl https://api.smartsheet.com/1.1/sheets -h "authorization: bearer 26lhbngfsybdayabz6afrc6dcd" -h "content-type: application/json" -x post -d @test.json', stdin=pipe, stdout=pipe)  out, err = p.communicate() print "output %s" % out print "error %s" % err 

although use urllib2 library because made kind of operation

check example using urrlib2 , reading response http://www.2maomao.com/blog/python-http-post-a-binary-file-using-urllib2/


Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -