[Twisted-Python] How to send response 401
justinjohnson at fastmail.fm
Tue Jun 10 10:50:40 EDT 2003
I tried the following and it seemed to work. Can someone let me know if
this is the correct way to do this in twisted?
def render(self, request):
headers = request.getAllHeaders()
log("User has authorization key: " + headers["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)
log("User not authorized")
On Tue, 10 Jun 2003 08:10:50 -0600, "Justin Johnson"
<justinjohnson at fastmail.fm> said:
> 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.
> 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)
> Twisted-Python mailing list
> Twisted-Python at twistedmatrix.com
More information about the Twisted-Python