how to use below curl command in python

143 Views Asked by At

Below is the curl command and wanted to use in python by using request. I am beginner to python. Appreciate advice/help.

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

2

There are 2 best solutions below

1
On

You can use Requests to POST data:

import requests

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

Requests is now a defacto standard.

0
On

Either use requests module or call it from a shell. So,

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