Reputation: 415
I was running on Python2.6 and Twisted 15.0.0 with this:
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
But after upgrading to Python3.7 and twisted latest (18.7.0) I can't get anything at http://localhost:8000/here
No Such Resource
No such child resource.
Can't find any twisted docs or examples that say a different way to do it.
Additional:
It is starting up the service fine, else I wouldn't see the above.
For reproduction purposes, the twisted/plugins/my_plugin.py looks like:
from twisted.application.service import ServiceMaker
svc = ServiceMaker("TEST_ONE",
"svc",
"Service",
"tstsvc"
)
And executed with:
twist tstsvc
Upvotes: 1
Views: 314
Reputation: 415
Mystery solved.
Of course it's Python3 here again with String handling.
root_resource.putChild(b"here", static.File('/tmp'))
Without the 'b' in front of the path, it never matched the url as typed.
Thought: Should the putChild() api throw an error if it's passed a str here? Seems bytes is always the right answer and the only thing that could match
Upvotes: 1