Execute curl command within a Python script

前端 未结 6 1561
轻奢々
轻奢々 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:39

    Rephrasing one of the answers in this post, instead of using cmd.split(). Try to use:

    import shlex
    
    args = shlex.split(cmd)
    

    Then feed args to subprocess.Popen.

    Check this doc for more info: https://docs.python.org/2/library/subprocess.html#popen-constructor

提交回复
热议问题