[Twisted-web] Get access to Avatar from Resource object?
Jacek Furmankiewicz
jacek99 at gmail.com
Thu Feb 23 11:28:56 EST 2012
I am trying to understand how it works in the context of twisted.web and
Resources, but I always get an exception on the portal object
Here is the core code:
passwords = {"admin":"password"}
users = {"admin":"Administrator"}
realm = TestRealm(users)
p = portal.Portal(TestRealm(users),(PasswordDictChecker(passwords),))
credentialFactory = BasicCredentialFactory("CorePost")
resource = HTTPAuthSessionWrapper(portal, [credentialFactory])
print "Running..."
factory = Site(resource)
reactor.listenTCP(8084, factory)
reactor.run()
Error:
Unhandled Error
Traceback (most recent call last):
File
"/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/protocols/basic.py",
line 564, in dataReceived
why = self.lineReceived(line)
File
"/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/http.py",
line 1551, in lineReceived
self.allContentReceived()
File
"/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/http.py",
line 1618, in allContentReceived
req.requestReceived(command, path, version)
File
"/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/http.py",
line 773, in requestReceived
self.process()
--- <exception caught here> ---
File
"/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/server.py",
line 131, in process
resrc = self.site.getResourceFor(self)
File
"/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/server.py",
line 562, in getResourceFor
return resource.getChildForRequest(self.resource, request)
File
"/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/resource.py",
line 65, in getChildForRequest
resource = resource.getChildWithDefault(pathElement, request)
File
"/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/_auth/wrapper.py",
line 142, in getChildWithDefault
return self._authorizedResource(request)
File
"/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/_auth/wrapper.py",
line 106, in _authorizedResource
return util.DeferredResource(self._login(Anonymous()))
File
"/usr/local/lib/python2.7/dist-packages/Twisted-12.0.0-py2.7-linux-x86_64.egg/twisted/web/_auth/wrapper.py",
line 152, in _login
d = self._portal.login(credentials, None, IResource)
*exceptions.AttributeError: 'module' object has no attribute 'login'*
*
*
Attached the full file.
Not sure I understand what I am doing right here. The app starts up fine,
but throws the error on any request.
Also, how do I hook up actual Resources?
Do I do it do the HttpAuthSessionWrapper? It is an IResources, but
complains that it does not have a putChild() on it?
Should my TestRealm extend a Resource and I add my child Resource there?
Sorry for all the questions, but the docs don't really cover the A-Z
scenario of getting a running twisted.web app with Http auth... :-(
Jacek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-web/attachments/20120223/d86735de/attachment-0001.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: security_resource.py
Type: text/x-python
Size: 2317 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20120223/d86735de/attachment-0001.py
More information about the Twisted-web
mailing list