- Twisted FileSender unable to send binary file due to UnicodeDecodeError
- Unhandled Error
- Traceback (most recent call last):
- Failure: exceptions.RuntimeError: Producer was not unregistered for /vfs/videos/thevid.avi
- Unhandled Error
- Traceback (most recent call last):
- File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithLogger
- return callWithContext({"system": lp}, func, *args, **kw)
- File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 69, in callWithContext
- return context.call({ILogContext: newCtx}, func, *args, **kw)
- File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
- return self.currentContext().callWithContext(ctx, func, *args, **kw)
- File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
- return func(*args,**kw)
- --- <exception caught here> ---
- File "/usr/lib/python2.7/dist-packages/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite
- why = getattr(selectable, method)()
- File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 428, in doWrite
- result = abstract.FileDescriptor.doWrite(self)
- File "/usr/lib/python2.7/dist-packages/twisted/internet/abstract.py", line 199, in doWrite
- self.dataBuffer = buffer(self.dataBuffer, self.offset) + "".join(self._tempDataBuffer)
- File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
- return codecs.utf_8_decode(input, errors, True)
- exceptions.UnicodeDecodeError: 'utf8' codec can't decode byte 0xd3 in position 6: invalid continuation byte
- Unhandled Error
- Traceback (most recent call last):
- Failure: exceptions.RuntimeError: Producer was not unregistered for /vfs/videos/thevid.avi
- def writeFile(self, request, location):
- # Setup headers (mime type, filename)
- request.setHeader('Content-Type', mimetypes.guess_type("file://" + location))
- request.setHeader('Content-Disposition', "attachment; filename=" + path.basename(location))
- # Open file
- handle = open(location, "rb")
- # Setup transfer (then cleanup etc)
- d = FileSender().beginFileTransfer(handle, request)
- def fileFinished(ignored):
- handle.close()
- request.finish()
- d.addCallback(fileFinished).addErrback(fileFinished)