I am looking for a Python equivalent for the curl command below.
curl http://localhost/x/y/update -H 'Content-type: text/xml; charset=utf-8' --data-binary @filename.xml
Incidentally, I normally post data as strings using the code below.
curl http://localhost/x/y/update --data '<data>the data is here</data>' -H 'Content-type:text/xml; charset=utf-8'
baseurl = http://localhost/x/y
thedata = '<data>the data is here</data>'
headers = {"Content-type": "text/xml", "charset": "utf-8"}
thequery = urlparse.urljoin(baseurl, thedata, querycontext)
therequest = urllib2.Request(thequery, headers)
theresponse = urllib2.urlopen(therequest)
Python requests its a great library for this kind of stuff. What you have there can be simply done by:
The problem of pycurl and some other url and http client libraries for python is that it requires more effort than the one you should need to achieve something relatively simple. requests its way more user friendly and I think its what you are looking for on this problem.
Hope this helps