subprocess.call(' curl https://api.smartsheet.com/1.1/sheets -H"授权:Bearer 26lhbngfsybdayabz6afrc6dcd" -H"内容类型:application / json" -X POST - d @ test.json')
我的test.json
有:
{
"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"
]
}
]
}
答案 0 :(得分:1)
试试这个:
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
虽然您可以使用urllib2库,因为这是为了那种操作
使用urrlib2检查此示例并阅读响应http://www.2maomao.com/blog/python-http-post-a-binary-file-using-urllib2/