How can I access the socket object from within a Twisted/Klein route method in Python?

223 Views Asked by At

I am using Twisted/Klein to create an API over UNIX-domain sockets for some command-line services I am writing. I would like to be able to get access to the socket object so that I can check the PEER CREDENTIALS for that socket to determine who has access to which methods of the API. Does anyone know of a way to access that socket object or, alternately, access the PEER CREDENTIALS data from a UNIX-domain socket in Klein/Twisted?

Thanks in advance!!

1

There are 1 best solutions below

2
On BEST ANSWER

In Klein, it would be request.channel.transport.getHandle().

The types of these objects are, respectively:

twisted.web.server.Request, twisted.web.http.HTTPChannel, twisted.internet.unix.Server, and socket.socket, respectively.