我有一个curl命令,该命令在我的unix server上工作。我想使用python脚本执行它。curl逗号:
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
我尝试了导入OS,并执行了curl buti Am Ar错误作为后的语法。我也尝试使用子过程
subprocess.Popen(curl 0)
,但没有运气。谁能帮我吗?
非常感谢,Apurva Acharya
您可以使用Python,子过程模块进行此操作
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)