By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,735 Members | 1,282 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,735 IT Pros & Developers. It's quick & easy.

Authentication for XML-RPC Calls

P: n/a
The only documentation regarding doing authentication for XML-RPC I
can find is -

"Both the HTTP and HTTPS transports support the URL syntax extension
for HTTP Basic Authentication: http://user:pass@host:port/path. The
user:pass portion will be base64-encoded as an HTTP `Authorization'
header, and sent to the remote server as part of the connection
process when invoking an XML-RPC method. You only need to use this if
the remote server requires a Basic Authentication user and password."

- from http://docs.python.org/lib/module-xmlrpclib.html

Is this really the only way to do authentication for XML-RPC calls?

Like this:
server = xmlrpclib.Server('http://adam:fred123@localhost/zidestore/so/
adam/'

This works, but is pretty ugly. Is there no way to setup the
authentication through properties (like in most XML-RPC bindings),
like:

server = xmlrpclib.Server('http://localhost/zidestore/so/adam/'
server.Username = 'adam'
server.Password = 'fred123'
Jul 22 '08 #1
Share this Question
Share on Google+
1 Reply

P: n/a
whitemice wrote:
The only documentation regarding doing authentication for XML-RPC I
can find is -

"Both the HTTP and HTTPS transports support the URL syntax extension
for HTTP Basic Authentication: http://user:pass@host:port/path. The
user:pass portion will be base64-encoded as an HTTP `Authorization'
header, and sent to the remote server as part of the connection
process when invoking an XML-RPC method. You only need to use this if
the remote server requires a Basic Authentication user and password."

- from http://docs.python.org/lib/module-xmlrpclib.html

Is this really the only way to do authentication for XML-RPC calls?

Like this:
server = xmlrpclib.Server('http://adam:fred123@localhost/zidestore/so/
adam/'

This works, but is pretty ugly. Is there no way to setup the
authentication through properties (like in most XML-RPC bindings),
like:

server = xmlrpclib.Server('http://localhost/zidestore/so/adam/'
server.Username = 'adam'
server.Password = 'fred123'
Just write a little factory class that does it for you:

import urlparse

class myauth(object):
def __init__(self, scheme = None, domain = None, path = None):
self.scheme = scheme
self.domain = domain
self.path = path
self.Username = None
self.Password = None

def __str__(self):

for attr in ['scheme', 'domain', 'path', 'Username', 'Password']:
if getattr(self, attr) is None:
raise ValueError('No %s attribute value given' % attr)

url=urlparse.urlunsplit((self.scheme,
'%s:%s@%s' % (self.Username, self.Password, self.domain),
self.path, '', ''))

return url

if __name__ == "__main__":
auth = auth = myauth(scheme = 'http', domain = 'localhost',
path='/zidestore/so/adam/')

auth.Username = 'adam'
auth.Password = 'fred123'
print auth
In program

auth = myauth(scheme = 'http', domain = 'localhost',
path = '/zidestore/so/adam')

auth.Username = 'adam'
auth.Password = 'fred123'

print auth

'http://adam:fr*****@docs.python.org/params;/lib/module-xmlrpclib.html'
>>>
-Larry
Jul 22 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.