我在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上什么也得不到
没有这样的资源 没有这样的儿童资源。
找不到任何扭曲的文档或例子,说明不同的方式来做它。
附加信息:
这是启动服务的好,否则我不会看到上面的。
出于复制目的,扭曲/plugins/my_plugin.py如下所示:
from twisted.application.service import ServiceMaker
svc = ServiceMaker("TEST_ONE",
"svc",
"Service",
"tstsvc"
)并在下列情况下执行:
twist tstsvc发布于 2018-08-18 08:27:06
谜团解开了。
当然,这里又是带有字符串处理的Python3。
root_resource.putChild(b"here", static.File('/tmp'))没有路径前面的'b‘,它就不会匹配键入的url。
想法:如果putChild() api在这里传递了一个str,那么它应该抛出一个错误吗?似乎字节总是正确的答案,也是唯一可以匹配的东西。
https://stackoverflow.com/questions/51905665
复制相似问题