XMLRPC Authentication

Justin Johnson justinjohnson at fastmail.fm
Fri Jun 6 13:54:50 EDT 2003


How do you specify the login id and password required on the server side?
 The code I'm using is similar to the following.  I'm obviously missing
something here... :-(  Thanks for your help.

# Server code

import SimpleXMLRPCServer
from ccservice import CCService # A class providing methods for remote
use

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("somehost", 8000))
server.register_instance(CCService())
server.serve_forever()



# Client code

import xmlrpclib
from BasicAuthTransport import BasicAuthTransport

server = xmlrpclib.Server('http://somehost:8000',
BasicAuthTransport("admin","password"))
print server.runCmd("dir")  # Call one of the remote methods








On Fri, 6 Jun 2003 12:31:29 -0700 (PDT), "Dave Brueck"
<dave at pythonapocrypha.com> said:
> On Fri, 6 Jun 2003, Justin Johnson wrote:
> > On Fri, 6 Jun 2003 12:13:26 -0700 (PDT), "Dave Brueck"
> > <dave at pythonapocrypha.com> said:
> > > On Fri, 6 Jun 2003, Justin Johnson wrote:
> > >
> > > > I have a simple xmlrpc server (using xmlrpclib) that accepts requests
> > > > from clients and runs some administrative commands on a bunch of servers
> > > > I support.  I would like to lock down access to the service so that only
> > > > authorized users can use it, by authenticating with a user name and
> > > > password.
> > > >
> > > > Has anyone done this before?  Is there an already existent authentication
> > > > framework available I can use with xmlrpc?
> > >
> > > I use the improvements to xmlrpclib listed here:
> > >
> > > http://www.zope.org/Members/Amos/XML-RPC
> 
> > Would you mind explaining to me how you use them?  In conjunction with
> > the example in the cookbook perhaps...
> 
> Assuming you've been using the XMLRPC client like this:
> 
> import xmlrpclib
> s = xmlrpclib.ServerProxy(url)
> 
> then you would use the BasicAuthTransport in that above HOWTO like this:
> 
> s = xmlrpclib.ServerProxy(url, BasicAuthTransport(username, password)
> 
> Everything else would remain the same. With a little work you could
> rewrite BasicAuthTransport to be a mixin to use with xmlrpclib's
> Transport
> and SafeTransport classes (thus enabling use over HTTPS as well).
> 
> -Dave
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 





More information about the Python-list mailing list