SimpleXMLRPCServer and client IP address
Fredrik Lundh
fredrik at pythonware.com
Wed Jun 28 11:25:51 EDT 2006
Jeremy Monnet wrote:
> Tips I've found were :
> - use the requestHandler and its method address_string(), but I didn't
> an easy to understand example
> - http://mail.python.org/pipermail/python-list/2006-May/340266.html
> but this thread seems not to have been finished :-(
maybe the explanation in that message was good enough for the poster ?
Your handler object should be getting set up with the client_address property.
If not you need to show us some small subset of your app that demonstrates the
issue.
You can also inherit from SimpleXMLRPCServer and override verify_request, from
BaseServer, if you want the option of blocking requests based on source
address.
the second alternative should be straightforward enough:
class MyXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer):
def verify_request(self, request, client_address):
return CheckPerms(client_address)
server = MyXMLRPCServer(...)
...
if you need more control, you need to subclass SimpleXMLRPCHandler instead.
> Furthermore, I think I should be able to access the socket object from
> where I am (at starting of isOpen() ), but I don't know how.
you cannot. the isOpen() function is your RPC handler, and it only sees things provided
by the client.
> "self" and "parent" are not defined, I can access the "server" object, but it
> says the other end s not connected ("transport endpoint"). I think
> this SimpleXMLRPCServer was not threaded (because it says in the API :
> "answer all requests one at a time"), so I don't understand why in the
> middle of my function the server.socket.getpeername() says it's not
> connected.
because the server socket isn't the same thing as the client socket -- the server socket
is only used to listen for incoming connections; it creates a new client socket for each
incoming request.
</F>
More information about the Python-list
mailing list