Execute curl command within a Python script

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

    Try with subprocess

    CurlUrl="curl 'https://www.example.com/' -H 'Connection: keep-alive' -H 'Cache- 
              Control: max-age=0' -H 'Origin: https://www.example.com' -H 'Accept-Encoding: 
              gzip, deflate, br' -H 'Cookie: SESSID=ABCDEF' --data-binary 'Pathfinder' -- 
              compressed"
    

    Use getstatusoutput to store the results

    status, output = subprocess.getstatusoutput(CurlUrl)
    

提交回复
热议问题