Re: Get access to Avatar from Resource object?

[email protected]
Newsgroups gmane.comp.python.twisted.web
Message-ID <20120223172806.28567.1322791924.divmod.xquotient.23@localhost6.localdomain6>
On 04:28 pm, [email protected] wrote:
>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),))

Your Portal instance is named `p`
>    credentialFactory = BasicCredentialFactory("CorePost")
>    resource = HTTPAuthSessionWrapper(portal, [credentialFactory])

But you pass in the `portal` module instead.

Jean-Paul
>    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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.