如何使用python 3.6 windows执行curl命令

时间:2017-12-04 11:07:00

标签: python windows

我有一个curl命令,它在我的UNIX服务器上运行。我想用python脚本执行它。 卷毛逗号:

curl -X POST -H "Content-type: application/vnd.appd.cntrl+json;v=1" -d '{"name":"Suppression_Testing","timeRange": {"startTimeMillis": "2017-12-25T04:16:30+0000","endTimeMillis": "2017-12-26T06:16:30+0000"},"affects": {"type": "APP"}}' --user api@adgm-nonprod:ac@123

https://apcn.adm.com/controller/api/accounts/3/applications/61/actionsuppressions

我尝试了导入操作系统并执行了curl但是我收到了错误,因为POST语法无效。 我也尝试使用子进程

subprocess.Popen(curl 0)但没有运气。任何人都可以帮助我吗?

非常感谢, Apurva Acharya

1 个答案:

答案 0 :(得分:0)

你可以使用python,subprocess模块​​来做到这一点

from subprocess import Popen
command='''curl -X POST -H "Content-type: application/vnd.appd.cntrl+json;v=1" -d '{"name":"Suppression_Testing","timeRange": {"startTimeMillis": "2017-12-25T04:16:30+0000","endTimeMillis": "2017-12-26T06:16:30+0000"},"affects": {"type": "APP"}}' --user api@adgm-nonprod:ac@123'''

#use shell=True , this will allow you to run the command in a single string on a shell like environment 

proc=Popen(command,shell=True)