How to get Hostname using SimpleXMLRPCServer

Golawala, Moiz M (GE Infrastructure) Moiz.Golawala at ge.com
Thu May 6 10:33:23 EDT 2004


Thank you, Brian for the reply.

I figured it out. I realized that in the SimpleXMLRPCRequestHandler there is a doPost method which is inherited from BaseHTTPRequestHandler. In the doPost method you can simply ask the self.header for the host variable (clientName = self.host["host"]) and you get the client that is invoking the call to the server. 

In using the address_string() method I had some problem, I would get exceptions that the address_string method needs an instance of the  SimpleXMLRPCRequestHandler as an argument. When I over-rode the address_string method in the SimpleXMLRPCRequestHandler class and passed in self as an argument I got the exception that an SimpleXMLRPCRequestHandler instance is required and instead it got a class. I could not figure out what that meant. 

class SimpleXMLRPCRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):

	def address_string(self):
		return BaseHTTPServer.BaseHTTPRequestHandler.address_string(self)

calling the address_string method from the SimpleXMLRPCServer will throw an exception saying that the a SimpleXMLRPCRequestHandler instance was expected, but got a class instead.

so the work around to this was what I mentioned in the first paragraph. I will simply create an instance variable to store the host name and have a getter to get the variable from the SimpleXMLRPCRequestHandler class.

Thanks
Moiz 

-----Original Message-----
From: Brian Quinlan [mailto:brian at sweetapp.com]
Sent: Thursday, May 06, 2004 9:45 AM
To: Golawala, Moiz M (GE Infrastructure); python-list at python.org
Subject: Re: How to get Hostname using SimpleXMLRPCServer


Golawala, Moiz M (GE Infrastructure) wrote:
> I have multiple xmlrpc clients talking to my  SimpleXMLRPCServer. When a method 
> on my server is invoked, I would like to know the hostname of the client that 
 > has invoked the method. Does anybody know how to get the client host 
name from
 > the xmlrpc request call to the SimpleXMLRPCServer. Any help is
> appreciated. 

Sorry I don't have time to actually write any example code for you, but 
you might want to look at the BaseHTTPServer documentation. 
SimpleXMLRPCRequestHandler is a subclass of 
BaseHTTPServer.BaseHTTPRequestHandler, which has a client_address 
instance variable and an address_string() method.

Let me know if you need any other help (and sorry for ignoring your post 
yesterday).

Cheers,
Brian





More information about the Python-list mailing list