List Info

Thread: CP3 + XMLRPC Issues




CP3 + XMLRPC Issues
country flaguser name
Australia
2007-06-07 07:59:22
Hi,

I have written a fairly simple XML-RPC server and client
that doesn't seem to work - I have successfully built a
general purpose XML-RPC server for my IRC bot, however I
can't seem to work out why I keep getting 404's here in
this case :/

http://paste.lisp
.org/display/42387

I would appreicate any help here, thsnk!

cheers
James

-- 
--
-"Problems are Solved by Method"
-
- James Mills <prologicshortcircuit.net.au>
- HomePage: http://shortcir
cuit.net.au/~prologic/
- IRC: irc://shortcircuit.net.au#se

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: CP3 + XMLRPC Issues
country flaguser name
United States
2007-06-07 12:54:10
James Mills wrote:
> I have written a fairly simple XML-RPC server and
client
> that doesn't seem to work - I have successfully built
a
> general purpose XML-RPC server for my IRC bot, however
I
> can't seem to work out why I keep getting 404's here
in
> this case :/

Yeah; XML-RPC is nasty. Here's the new docstring I just
wrote for
_cptools.XMLRPCController. Hope it helps.


class XMLRPCController(object):
    """A Controller (page handler collection)
for XML-RPC.
    
    To use it, have your controllers subclass this base
class (it will
    turn on the tool for you).
    
    You can also supply the following optional config
entries:
        
        tools.xmlrpc.encoding: 'utf-8'
        tools.xmlrpc.allow_none: 0
    
    XML-RPC is a rather discontinuous layer over HTTP;
dispatching to
the
    appropriate handler must first be performed according to
the URL,
and
    then a second dispatch step must take place according to
the RPC
method
    specified in the request body. It also allows a
superfluous "/RPC2"
    prefix in the URL, supplies its own handler args in the
body, and
    requires a 200 OK "Fault" response instead of
404 when the desired
    method is not found.
    
    Therefore, XML-RPC cannot be implemented for CherryPy
via a Tool
alone.
    This Controller acts as the dispatch target for the
first half
(based
    on the URL); it then reads the RPC method from the
request body and
    does its own second dispatch step based on that method.
It also
reads
    body params, and returns a Fault on error.
    
    The XMLRPCDispatcher strips any /RPC2 prefix; if you
aren't using
/RPC2
    in your URL's, you can safely skip turning on the
XMLRPCDispatcher.
    Otherwise, you need to declare it in config:
        
        request.dispatch:
cherrypy.dispatch.XMLRPCDispatcher()
    """


Robert Brewer
System Architect
Amor Ministries
fumanchuamor.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: CP3 + XMLRPC Issues
country flaguser name
Australia
2007-06-09 18:54:07
Hi,

Thank you for the update docstring - however it hasn't
helped I'm afraid :/ I cannot for the life of me get
a simple server/client working.

Here is what I have:

Server:

#!/usr/bin/env python

# Filename: authd.py
# Module:	authd
# Date:		7th June 2007
# Author:	James Mills, prologic at shortcircuit dot net dot
au

"""Authentication Daemon

Authentication Daemon for Zannee Broker Recruiting System.
"""

__description__ = "uthentication Daemon"
__version__ = "0.0.1"
__author__ = "James Mills"
__author_email__ = "%s, prologic at shortcircuit dot
net dot au" % __author__
__url__ = "http://sh
ortcircuit.net.au/~prologic/"
__copyright__ = "CopyRight (C) 2007 by %s" %
__author__
__license__ = "GPL"

import os
cwd = os.path.join(os.getcwd())

CA = os.path.join(cwd, "authd.crt")
KEY = os.path.join(cwd, "authd.key")

import cherrypy
from cherrypy import expose
from cherrypy._cptools import XMLRPCController

from pymills.db import Connection as DBConnection

HTTPS_PORT = 9000
DATABASE = "mysql://prologic:4105701518data/prologic_recruits"

def newDB(idx): 
	cherrypy.thread_data.db = DBConnection(DATABASE)

def delDB(idx): 
	if hasattr(cherrypy.thread_data, "db"):
		del cherrypy.thread_data.db

class Root(XMLRPCController):
	
	db = property(lambda f: cherrypy.thread_data.db)
	req = property(lambda f: cherrypy.request)

	expose
	def index(self, *args, **kwargs):
		print "index"
		return "Hello"

	expose
	def login(self, **kwargs):
		print "login"
		return ["Not Implemented"]

def main():
	cherrypy.engine.on_start_thread_list.append(newDB)
	cherrypy.engine.on_stop_thread_list.append(delDB)

	cherrypy.config.update("authd.ini")

	conf = {
			"/": {
				"request.dispatch":
cherrypy.dispatch.XMLRPCDispatcher()
				}
			}

	root = Root()
	cherrypy.tree.mount(root, "/", conf)
	cherrypy.server.quickstart()
	cherrypy.engine.start()

if __name__ == "__main__":
	main()

Client:

#!/usr/bin/env python

import socket
import xmlrpclib
from traceback import format_exc

URL = "https://localhost:9000/
"

def main():
	try:
		server = xmlrpclib.ServerProxy(URL)
		print server.login("test", "test")
	except Exception, e:
		if isinstance(e, socket.error):
			if e[0] == 111:
				print "ERROR: %s" % e[1]
		else:
			print "ERROR: %s" % e
			print format_exc()

if __name__ == "__main__":
	import sys
	main(*sys.argv[1:])

----

When I run the client, I get nothing back.
I've also discovered that it maps to the index method.
DOn't
know why. If you remove the trailing / from the url you get
a 302.

I cannot seem to access that pesky login method.
But I also get nothing back on anything else.

It all works in a Web Browser though - which makes me
wonder what's going on with the XML-RPC side.

cheers
James

-- 
--
-"Problems are Solved by Method"
-
- James Mills <prologicshortcircuit.net.au>
- HomePage: http://shortcir
cuit.net.au/~prologic/
- IRC: irc://shortcircuit.net.au#se

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: CP3 + XMLRPC Issues
country flaguser name
Australia
2007-06-13 18:58:13
Hi,

Just wondering whether anyone has looked at this yet ?
I cannot solve this - I've tried everything. I don't
understand why my bot's xmlrpc plugin works but not this
simple server/client example.

See: previous msgs in thread.

cheers
James

-- 
--
-"Problems are Solved by Method"
-
- James Mills <prologicshortcircuit.net.au>
- HomePage: http://shortcir
cuit.net.au/~prologic/
- IRC: irc://shortcircuit.net.au#se

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: CP3 + XMLRPC Issues
country flaguser name
United States
2007-06-15 13:57:45
On Jun 9, 4:54 pm, James Mills <prolo...shortcircuit.net.au> wrote:
> Server:
>
> import cherrypy
> from cherrypy import expose
> from cherrypy._cptools import XMLRPCController
>
> HTTPS_PORT = 9000
>
> class Root(XMLRPCController):
>
>         expose
>         def index(self, *args, **kwargs):
>                 print "index"
>                 return "Hello"
>
>         expose
>         def login(self, **kwargs):
>                 print "login"
>                 return ["Not Implemented"]
>
> def main():
>         cherrypy.config.update("authd.ini")
>         conf = {"/":
{"request.dispatch":
cherrypy.dispatch.XMLRPCDispatcher()}}
>         root = Root()
>         cherrypy.tree.mount(root, "/", conf)
>         cherrypy.server.quickstart()
>         cherrypy.engine.start()
>
> if __name__ == "__main__":
>         main()
>
> Client:
>
> #!/usr/bin/env python
>
> import socket
> import xmlrpclib
> from traceback import format_exc
>
> URL = "https://localhost:9000/
"
>
> def main():
>         try:
>                 server = xmlrpclib.ServerProxy(URL)
>                 print server.login("test",
"test")
>         except Exception, e:
>                 if isinstance(e, socket.error):
>                         if e[0] == 111:
>                                 print "ERROR:
%s" % e[1]
>                 else:
>                         print "ERROR: %s" %
e
>                         print format_exc()
>
> if __name__ == "__main__":
>         import sys
>         main(*sys.argv[1:])
>
> ----
>
> When I run the client, I get nothing back.
> I've also discovered that it maps to the index method.
DOn't
> know why. If you remove the trailing / from the url you
get
> a 302.
>
> I cannot seem to access that pesky login method.
> But I also get nothing back on anything else.
>
> It all works in a Web Browser though - which makes me
> wonder what's going on with the XML-RPC side.

I had a chance to test this finally, and found several
issues. I got
your example code to work by performing the following 3
steps:

1) Something's wrong with Python's xmlrpclib when doing
HTTPS. See the
HTTPSTransport class in cherrypy/test/test_xmlrpc.py for how
we get
around that in the test suite.

2) The XMLRPCController base class already has an index
method, and
when you override it, you break the controller. The existing
index
method is the page handler that CherryPy calls to handle the
XMLRPC.
It should be possible to construct a different XMLRPC
solution for CP
that doesn't use an "index" method...but I'm not
going to attempt that
here. For now, just comment out your custom index method to
get the
ball rolling.

3) Any params sent to the RPC method are sent as positional
args, not
keyword args, so your login method's signature should more
properly be
something like "def login(self, *args):". Using
that sig, I got back
the correct ['Not Implemented'] response.


Robert Brewer
System Architect
Amor Ministries
fumanchuamor.org


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "cherrypy-users" group.
To post to this group, send email to cherrypy-usersgooglegroups.com
To unsubscribe from this group, send email to
cherrypy-users-unsubscribegooglegroups.com
For more options, visit this group at h
ttp://groups.google.com/group/cherrypy-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )