我正在尝试运行此基本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.5
在twisted 18.7.0
中一起工作。您能否使用twisted
向我提供一个简单的HTTPAuthSessionWrapper
工作示例?