扭曲升级 - 现在无法访问站点路径



我在 Python2.6 和 Twisted 15.0.0 上运行:

from twisted.python import usage
from twisted.web import resource, server, static
from twisted.application import internet
class Options(usage.Options):
optParameters = [
]
def makeService(options):
# this variation works
root_resource = static.File('/tmp')
# this variation doesn't
root_resource = resource.Resource()
root_resource.putChild("here", static.File('/tmp'))
site = server.Site(root_resource)
web_svc = internet.TCPServer(8000, site)
return web_svc

但是升级到 Python3.7 并扭曲最新 (18.7.0( 后,我无法在 http://localhost:8000/here

没有这样的资源

没有这样的子资源。

找不到任何扭曲的文档或示例来说明不同的方法。

附加:

它正在正常启动服务,否则我不会看到上述内容。

出于复制目的,扭曲/插件/my_plugin.py看起来像:

from twisted.application.service import ServiceMaker
svc = ServiceMaker("TEST_ONE",
"svc",
"Service",
"tstsvc"
)

并执行:

twist tstsvc

谜团解开了。

当然,这里又是 Python3 的字符串处理。

root_resource.putChild(b"here", static.File('/tmp'))

路径前面没有"b",它永远不会与键入的 url 匹配。

思想:如果 putChild(( API 在这里传递了一个 str,它应该抛出错误吗?似乎字节总是正确的答案,也是唯一可以匹配的东西

最新更新