[Twisted-Python] How to send response 401
Justin Johnson
justinjohnson at fastmail.fm
Tue Jun 10 08:10:50 MDT 2003
I have an xmlrpc service inheriting from xmlrpc.XMLRPC. I override
render to allow for basic authentication as show below. This all works,
except that I don't know what to call to send response 401 back to the
client. self.send_response(401) is how I would do it with the
SimpleXMLRPCServer, but obviously doesn't work with the twisted xmlrpc
server. Can someone point me in the right direction on this?
Thanks much.
-Justin
P.S. - Moshe, I figured out everything else I asked you on the
python-list about this. Just need to know how to send response 401 now.
Before I wasn't seeing the header, because request.headers doesn't
contain all headers. Had to use request.getAllHeaders().
def render(self, request):
headers = request.getAllHeaders()
if headers.has_key("authorization"):
real_auth = '%s:%s' % (config.adminUser, config.adminPassword)
auth = headers["authorization"]
auth = auth.replace("Basic ","")
decoded_auth = decodestring(auth)
if decoded_auth == real_auth:
return xmlrpc.XMLRPC.render(self, request)
else:
self.send_response(401)
self.end_headers()
More information about the Twisted-Python
mailing list