简体   繁体   中英

How to execute curl command using python 3.6 windows

I have a curl command, Which works on my UNIX server.I want to execute it using python script. curl comma:

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

I tried import os and executed curl butI am getting error as POST invalid syntax. Also I tried using subprocess

subprocess.Popen(curl 0) but no luck. Can anyone help me?

Many Thanks, Apurva Acharya

you can use python , subprocess module to do this

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM