[Twisted-Python] How to send response 401
Itamar Shtull-Trauring
itamar at itamarst.org
Tue Jun 10 11:39:20 MDT 2003
On Tue, 10 Jun 2003 08:10:50 -0600
"Justin Johnson" <justinjohnson at fastmail.fm> wrote:
> 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()
Note you can do request.getUser() and request.getPassword(), IIRC,
instead of parsing the Basic auth header yourself.
More information about the Twisted-Python
mailing list