[Twisted-Python] XMLRPC Class in HTTP Server.
I'm not sure how the twisted web server works (I'm a new guy around here!), but it looks like your dictionary, pages, maps url's to callables. But MyConverterXMLRPCClass() is an instance, that is not callable (no __call__ method). I think what you want to do is something like this -> '/xmlrpc_converter': MyConverterXMLRPCClass().xmlrpc_mymethod1 ^^ Should get you past the __call__ error you're getting. HTH! jw On 7/6/07, Daniel de la Cuesta <daniel.cuesta@iavante.es> wrote:
Hi,
I have a twisted web server running using "twisted.web.http".
The objective of the server is to convert files to another format. Currently I upload the files and the conversion params using an HTTP POST from a form.
Now I want to add XML-RPC support to the conversion process. It means the user could process the conversion using the http form or calling directly the XML-RPC class.
This is my pages dispatch:
class MyRequestHandler(http.Request):
pages = { '/' : loginPage, '/uploadHandler' : handleUpload, '/uploadform' : uploadForm, '/xmlrpc_converter': MyConverterXMLRPCClass() }
What I want to do is offer the user two possibilities to upload the file, one of them using HTTP POST (calling to "uploadform") and the other using XML-RPC (caling to xmlrpc_converter).
I have tried to implement MyConverterXMLRPCClass() as follows:
MyConverterXMLRPCClass(xmlrpc.XMLRPC):
def __init(self): """""" pass
def xmlrpc_mymethod1(self, param) """My process""
But It down't work, when I try http://localhost:8000/xmlrpc_converter I get the following error:
"MyConverterXMLRPCClass instance has no __call__ method"
How can I call MyConverterXMLRPCClass from an url in my http server?
Thank you.
--
*Daniel de la Cuesta Navarrete* *Técnico de Desarrollo de Software*
FUNDACIÓN IAVANTE daniel.cuesta@iavantefundacion.com Tel. 951 015 300
Este correo electrónico y, en su caso, cualquier fichero anexo, contiene información confidencial exclusivamente dirigida a su(s) destinatario(s). Toda copia o divulgación deberá ser autorizada por IAVANTE.
This e-mail and any attachments are confidential and exclusively directed to its adressee(s). Any copy or distribution will have to be authorized by IAVANTE.
_______________________________________________ Twisted-Python mailing list Twisted-Python@twistedmatrix.com http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python
-- "Government does not solve problems; it subsidizes them." Ronald Reagan
Daniel de la Cuesta wrote:
Ok, but this is not exactly what I want.
The xml-rpc server is a web resource node, so to make things work, you need to call the render() method on your xml-rpc instance, so in your url map, instead of... MyConverterXMLRPCClass() use... MyConverterXMLRPCClass().render to store a bound reference to the render method and then all you need to do is call that and pass it the request object. The render method will take care of setting up deferreds to write the response or any errors back to the client. -- Jason Fritcher Senior Software Engineer Core Infrastructure Services & Strategy Earthlink, Inc fritcher@corp.earthlink.net
Wasn't going to reply to this, for reasons which will be obvious momentarily, but I haven't seen a correct reply yet, so... On Fri, 06 Jul 2007 09:46:38 +0200, Daniel de la Cuesta <daniel.cuesta@iavante.es> wrote:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> Hi,<br> <br> I have a twisted web server running using "twisted.web.http".<br> <br>
You probably want to direct future questions on this topic to the twisted-web mailing list, where you'll get more attention from people more actively doing web things.
The objective of the server is to convert files to another format. Currently I upload the files and the conversion params using an HTTP POST from a form.<br> <br> Now I want to add XML-RPC support to the conversion process. It means the user could process the conversion using the http form or calling directly the XML-RPC class.<br>
HTTP POST is probably a better way to upload files, in general. MIME-ish encoding is a bit easier and has less overhead than base64 encoding.
<br> This is my pages dispatch:<br> <br> class MyRequestHandler(http.Request):<br> <br> <br> pages = { '/' : loginPage, <br> '/uploadHandler' : handleUpload,<br> '/uploadform' : uploadForm,<br> '/xmlrpc_converter': MyConverterXMLRPCClass() }<br>
Rarely is it correct to subclass Request. You can probably just discard all of the above code. Aside from that, I don't know what the `pages' attribute is. I don't think anything pays any attention to it.
<br> What I want to do is offer the user two possibilities to upload the file, one of them using HTTP POST (calling to "uploadform") and the other using XML-RPC (caling to xmlrpc_converter).<br> <br> I have tried to implement MyConverterXMLRPCClass() as follows:<br> <br> MyConverterXMLRPCClass(xmlrpc.XMLRPC):<br> <br> def __init(self):<br> """"""<br> pass<br> <br> def xmlrpc_mymethod1(self, param)<br> """My process""<br> <br>
This part looks okay.
But It down't work, when I try <a class="moz-txt-link-freetext" href="http://localhost:8000/xmlrpc_converter">http://localhost:8000/xmlrpc_converter</a> I get the following error:<br> <br> "MyConverterXMLRPCClass instance has no __call__ method"<br> <br> How can I call MyConverterXMLRPCClass from an url in my http server?<br>
I don't know how a MyConverterXMLRPCClass got called. I suppose you have some more code that you didn't include in this message which looks at the pages dictionary on the request object and does something with them. Whatever it is, I guess it isn't correct. ;) Instead, what you should do is define a root resource which has MyConverterXMLRPCClass as a child at the "xmlrpc_converter" segment. You can do this pretty easily using the basic Resource class in twisted.web: from twisted.web.resource import Resource from twisted.web.server import Site from twisted.internet import reactor root = Resource() root.putChild('xmlrpc_converter', MyConverterXMLRPCClass()) site = Site(root) reactor.listenTCP(8080, site) The Resource class is implemented to keep track of child resources added to it with putChild so that when a request comes in for one of them, it gives back the appropriate one and URL traversal or page rendering can continue. Hope this helps, Jean-Paul
participants (4)
-
Daniel de la Cuesta
-
Jaime Wyant
-
Jason Fritcher
-
Jean-Paul Calderone