【问题标题】:Twisted upgrade - now can't access site paths扭曲升级 - 现在无法访问站点路径
【发布时间】:2018-08-18 05:46:08
【问题描述】:

我在 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 什么都得不到

没有这样的资源

没有这样的子资源。

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

补充:

它正在启动服务,否则我看不到上面的内容。

出于复制目的,twisted/plugins/my_plugin.py 看起来像:

from twisted.application.service import ServiceMaker

svc = ServiceMaker("TEST_ONE",
               "svc",
               "Service",
               "tstsvc"
               )

并执行:

twist tstsvc

【问题讨论】:

    标签: python-3.x twisted twisted.web


    【解决方案1】:

    谜团解开了。

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

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

    路径前面没有'b',它永远不会匹配输入的url。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-02-26
      • 2023-04-01
      • 1970-01-01
      • 2021-12-18
      • 2019-01-21
      • 1970-01-01
      • 2022-01-04
      • 1970-01-01
      相关资源
      最近更新 更多