【问题标题】:how to use below curl command in python如何在python中使用下面的curl命令
【发布时间】:2018-02-10 08:45:57
【问题描述】:

下面是curl命令,想在python中使用request。我是python的初学者。感谢建议/帮助。

curl --header 'Content-Type: text/xml;charset=UTF-8' --data-binary @c:/abcd.xml -X POST http://www.dneonline.com/calculator.asmx

【问题讨论】:

    标签: python curl pycurl


    【解决方案1】:

    您可以使用Requests POST 数据:

    import requests
    
    url = 'http://www.dneonline.com/calculator.asmx'
    files = {'c': open('/abcd.xml', 'rb')}
    r = requests.post(url, files=files)
    

    Requests 现在是事实上的标准。

    【讨论】:

    • 您需要更多解释吗?我建议你投票并accept我的回答。
    【解决方案2】:

    要么使用requests 模块,要么从外壳调用它。 所以,

    from subprocess import call
    call("curl --header 'Content-Type: text/xml;charset=UTF-8' --data-binary @c:/abcd.xml -X POST",shell=True) 
    

    【讨论】:

      猜你喜欢
      • 2016-08-15
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 2018-10-04
      • 1970-01-01
      • 2017-02-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多