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:

Server:
-------------------

import SimpleXMLRPCServer
import os.path

monitor = None

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

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

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

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 ('127.0.0.1', 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__
self.handle()
File "/usr/lib/python2.6/BaseHTTPServer.py", line 329, in handle
self.handle_one_request()
File "/usr/lib/python2.6/BaseHTTPServer.py", line 323, in handle_one_request
method()
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,
~twistedphrame

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'
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.