请在Python 3.6中提供简单的HTTPAuthSessionWrapper扭曲示例

时间:2018-10-03 22:52:07

标签: twisted twisted.web

我正在尝试运行此基本HTTP身份验证示例,该示例我发现here但未成功。因此,我尝试通过这种方式进一步简化:

from zope.interface import implementer

from twisted.cred.portal import IRealm, Portal
from twisted.web.static import File
from twisted.web.resource import IResource
from twisted.web.guard import HTTPAuthSessionWrapper, BasicCredentialFactory
from twisted.cred.checkers import InMemoryUsernamePasswordDatabaseDontUse
from twisted.python import log
import sys
from twisted.internet import reactor
from twisted.web import server, resource

@implementer(IRealm)
class PublicHTMLRealm(object):
    def requestAvatar(self, avatarId, mind, *interfaces):
        if IResource in interfaces:
            return (IResource, File("/home"), lambda: None)
        raise NotImplementedError()


log.startLogging(sys.stdout)

checkers = [InMemoryUsernamePasswordDatabaseDontUse(joe='blow')]

portal = Portal(PublicHTMLRealm(), checkers)

credentialFactory = BasicCredentialFactory('auth')

resource = HTTPAuthSessionWrapper(portal, [credentialFactory])

reactor.listenTCP(8889, server.Site(resource = resource))
reactor.run()

但是,该人也无法与python 3.6.5twisted 18.7.0中一起工作。您能否使用twisted向我提供一个简单的HTTPAuthSessionWrapper工作示例?

0 个答案:

没有答案