Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 4th, 2012  |  syntax: None  |  size: 2.24 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Twisted FileSender unable to send binary file due to UnicodeDecodeError
  2. Unhandled Error
  3. Traceback (most recent call last):
  4. Failure: exceptions.RuntimeError: Producer was not unregistered for /vfs/videos/thevid.avi
  5. Unhandled Error
  6. Traceback (most recent call last):
  7.   File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 84, in callWithLogger
  8.     return callWithContext({"system": lp}, func, *args, **kw)
  9.   File "/usr/lib/python2.7/dist-packages/twisted/python/log.py", line 69, in callWithContext
  10.     return context.call({ILogContext: newCtx}, func, *args, **kw)
  11.   File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 118, in callWithContext
  12.     return self.currentContext().callWithContext(ctx, func, *args, **kw)
  13.   File "/usr/lib/python2.7/dist-packages/twisted/python/context.py", line 81, in callWithContext
  14.     return func(*args,**kw)
  15. --- <exception caught here> ---
  16.   File "/usr/lib/python2.7/dist-packages/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite
  17.     why = getattr(selectable, method)()
  18.   File "/usr/lib/python2.7/dist-packages/twisted/internet/tcp.py", line 428, in doWrite
  19.     result = abstract.FileDescriptor.doWrite(self)
  20.   File "/usr/lib/python2.7/dist-packages/twisted/internet/abstract.py", line 199, in doWrite
  21.     self.dataBuffer = buffer(self.dataBuffer, self.offset) + "".join(self._tempDataBuffer)
  22.   File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
  23.     return codecs.utf_8_decode(input, errors, True)
  24. exceptions.UnicodeDecodeError: 'utf8' codec can't decode byte 0xd3 in position 6: invalid continuation byte
  25. Unhandled Error
  26. Traceback (most recent call last):
  27. Failure: exceptions.RuntimeError: Producer was not unregistered for /vfs/videos/thevid.avi
  28.        
  29. def writeFile(self, request, location):
  30.     # Setup headers (mime type, filename)
  31.     request.setHeader('Content-Type', mimetypes.guess_type("file://" + location))
  32.     request.setHeader('Content-Disposition', "attachment; filename=" + path.basename(location))
  33.  
  34.     # Open file
  35.     handle = open(location, "rb")
  36.  
  37.     # Setup transfer (then cleanup etc)
  38.     d = FileSender().beginFileTransfer(handle, request)
  39.     def fileFinished(ignored):
  40.         handle.close()
  41.         request.finish()
  42.     d.addCallback(fileFinished).addErrback(fileFinished)