I have the curious problem where I have a xmlrpc client
and requests
work fine with the Cherrypy server. I however, noticed that the curl command does not work. I get:
raise cherrypy.HTTPError(404, message=message)
cherrypy._cperror.HTTPError: (404, 'Missing parameters: data')
My cherrypy function is simple:
class XML(cherrypy._cptools.XMLRPCController):
@cherrypy.expose
def POST(self, data):
cherrypy.response.headers['Content-Type'] = 'application/xml'
return data
#Option 1
headers = {'Content-Type': 'application/xml'}
r = requests.post('http://localhost:8080/XML/POST',
data=data,
headers=headers,
stream=True)
#Option 2
xml_client = xmlrpc.client.ServerProxy('http://localhost:8080/XML/POST')
xml_client.POST(data)
The option that does not work is:
curl --form data=@data.xml -i -X POST 'http://localhost:8080/XML/POST/' -H 'Content-Type multipart/form-data' -H 'Accept application/soap+xml'
I would like to know why curl is not working with cherrypy the way the other two are working. I did try to find a reason but could not! Any suggestions will be much appreciated!
EDIT:
Thanks to @cyraxjoe
For the answer, however as this is part of the solution, I want to make it easier to find. Found out that people suggest REST instead of XML-RPC for various of reasons, one could take a look here. So I have removed the XMLRPCController
class XML():
@cherrypy.expose
def POST(self):
cherrypy.response.headers['Content-Type'] = 'application/xml'
data = cherrypy.request.body.read()
return data
Hopefully this will help someone else as well!
I think that you have to put colons in the header (-H
) options for curl.
curl --form data=@data.xml -i -X POST \
-H 'Content-Type: multipart/form-data' \
-H 'Accept: application/soap+xml' 'http://localhost:8080/XML/POST/'
Without them, the Accept
header is not configured. You can see what curl sends with the -v
option.