[Twisted-Python] Basic HTTP Authentication in Twisted.web
Allen Chan
user143 at tsolver.com
Wed Feb 19 06:39:58 EST 2003
The following test.rpy works for me in MSIE:
from twisted.protocols import http
from twisted.web import resource,error
class AuthResource(resource.Resource):
def __init__(self):
resource.Resource.__init__(self)
def render(self, request):
if not request.getUser() or not request.getPassword():
request.setHeader('WWW-authenticate', 'Basic realm="%s"' %
("default"))
errpage = error.ErrorPage(http.UNAUTHORIZED,"Unauthorized","401
Authentication required")
return errpage.render(request)
else:
return "<html><head></head><body>Hello World</body></html>\n"
resource = AuthResource()
-----Original Message-----
>From: "Thomas Weholt" <2002 at weholt.org>
>To: <twisted-python at twistedmatrix.com>
>Subject: Re: [Twisted-Python] Basic HTTP Authentication in Twisted.web
>Date: Wed, 19 Feb 2003 00:07:05 +0100
>Reply-To: twisted-python at twistedmatrix.com
>
>Thanks for the tip.
>
>Changed the code to use the same content for both the body and the
>Content-Length-header. Still no go. Isn't there a special Twisted way of
>doing this? My curreny solution is as I said earlier a dirty hack based on
>code from BaseHTTPServer.
>
>Anybody else has this kind of authentication going in their application who
>can spare a few lines of code as an example ???
>
>Thomas
More information about the Twisted-Python
mailing list