Execute curl command within a Python script

前端 未结 6 1556
轻奢々
轻奢々 2020-12-02 06:42

I am trying to execute a curl command within a python script.

If I do it in the terminal, it looks like this:

curl -X POST -d  \'{\"nw_src\": \"10.0.         


        
6条回答
  •  隐瞒了意图╮
    2020-12-02 07:27

    If you are not tweaking the curl command too much you can also go and call the curl command directly

    import shlex
    cmd = '''curl -X POST -d  '{"nw_src": "10.0.0.1/32", "nw_dst": "10.0.0.2/32", "nw_proto": "ICMP", "actions": "ALLOW", "priority": "10"}' http://localhost:8080/firewall/rules/0000000000000001'''
    args = shlex.split(cmd)
    process = subprocess.Popen(args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = process.communicate()
    

提交回复
热议问题