Subclassification static.File

I am new to Twisted and am having problems with some necessary subclass for static.File in twisted. I am trying to set request headers in a subclass.

class ResponseFile(static.File):

    def render_GET(self, request):
        request.setHeader('Content-Disposition', ['attachment ; filename="tick_db_export.csv"'])
        static.File.render_GET(self, request)

if __name__ == "__main__":
    from twisted.internet import reactor
    root = ResponseFile('WebFolder')
    testHandler = TestHandler()
    root.putChild('main', testHandler)
    reactor.listenTCP(3650, server.Site(root))
    reactor.run()

The first bit of code is the definition of a subclass (quite simple), and the second bit is part of the initialization from my code (this is not all my code). I also subclassed the resource. Resource object called TestHandler. WebFolder is another folder containing many static files.

However, when making calls to the server, I get most of these types of exceptions.

Unhandled Error
Traceback (most recent call last):
Failure: exceptions.RuntimeError: Producer was not unregistered for /

With many different paths other than root.

+5
source share
1 answer

render_GET. . NOT_DONE_YET . render_GET None ( ).

, render_GET ( return):

def render_GET(self, request):
    request.setHeader('Content-Disposition', ['attachment ; filename="tick_db_export.csv"'])
    return static.File.render_GET(self, request)

twisted.web.static.py, , File.render_GET NOT_DONE_YET, , ( ).

+4

All Articles