Hello all,

I'm having an issue with getting the ip address of a client accessing an xmlrpcserver, some of the time the code will work and then when I go to transfer the classes/methods (copy and paste) into my other file neither work and both have the same error:


import SimpleXMLRPCServer
import os.path

monitor = None

class ServerMethods:
def getMyIP(self):
return "your IP is: %s:%s" % (monitor.clientIP,

class myHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
def do_POST(self):
global monitor
monitor.clientIP, monitor.clientPort = self.client_address

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost",8888), myHandler)
serverhand = ServerMethods()

Client Call:

import xmlrpclib
host = "localhost"
port = 8888
serv = xmlrpclib.ServerProxy(host+":"+str(port))
d = serv.getMyIP()
print d

The error in the server is:
Exception happened during processing of request from ('', 58058)
Traceback (most recent call last):
File "/usr/lib/python2.6/SocketServer.py", line 281, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 307, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.6/SocketServer.py", line 320, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.6/SocketServer.py", line 615, in __init__
File "/usr/lib/python2.6/BaseHTTPServer.py", line 329, in handle
File "/usr/lib/python2.6/BaseHTTPServer.py", line 323, in handle_one_request
File "server.py", line 56, in do_POST
monitor.clientIP, monitor.clientPort = self.client_address
AttributeError: 'NoneType' object has no attribute 'clientIP'

Thank you for you help,

Your global variable monitor was initialized to None and never modified. Python won't set a 'clientIP' attribute for the None object:

>>> None.clientIP = "foo"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'clientIP'
This article has been dead for over six months. Start a new discussion instead.