[Twisted-Python] Twisted FTP: Data must not be unicode

Adi Roiban adi at roiban.ro
Thu Nov 24 07:00:46 MST 2011


On Jo, 2011-11-24 at 05:49 -0800, Tobias Oberstein wrote:
> Should I file a bug? If so, any guidelines what to do?
> 
>         --- <exception caught here> ---
>           File "/home/autobahn/python/lib/python2.7/site-packages/Twisted-11.1.0_r33225-py2.7-freebsd-8.2-RELEASE-p3-i386.egg/twisted/internet/defer.py", line 545, in _runCallbacks
>             current.result = callback(current.result, *args, **kw)
>           File "/home/autobahn/python/lib/python2.7/site-packages/Twisted-11.1.0_r33225-py2.7-freebsd-8.2-RELEASE-p3-i386.egg/twisted/protocols/ftp.py", line 907, in gotListing
>             self.dtpInstance.sendListResponse(name, attrs)
>           File "/home/autobahn/python/lib/python2.7/site-packages/Twisted-11.1.0_r33225-py2.7-freebsd-8.2-RELEASE-p3-i386.egg/twisted/protocols/ftp.py", line 421, in sendListResponse
>             self.sendLine(self._formatOneListResponse(name, *response))
>           File "/home/autobahn/python/lib/python2.7/site-packages/Twisted-11.1.0_r33225-py2.7-freebsd-8.2-RELEASE-p3-i386.egg/twisted/protocols/ftp.py", line 385, in sendLine
>             self.transport.write(line + '\r\n')
>           File "/home/autobahn/python/lib/python2.7/site-packages/Twisted-11.1.0_r33225-py2.7-freebsd-8.2-RELEASE-p3-i386.egg/twisted/internet/_newtls.py", line 180, in write
>             FileDescriptor.write(self, bytes)
>           File "/home/autobahn/python/lib/python2.7/site-packages/Twisted-11.1.0_r33225-py2.7-freebsd-8.2-RELEASE-p3-i386.egg/twisted/internet/abstract.py", line 300, in write
>             raise TypeError("Data must not be unicode")
>         exceptions.TypeError: Data must not be unicode
> 
> 
> [autobahn at autobahnhub ~/Twisted]$ svn diff twisted/protocols/ftp.py
> Index: twisted/protocols/ftp.py
> ===================================================================
> --- twisted/protocols/ftp.py    (revision 33225)
> +++ twisted/protocols/ftp.py    (working copy)
> @@ -382,7 +382,7 @@
>              self._onConnLost.callback(None)
> 
>      def sendLine(self, line):
> -        self.transport.write(line + '\r\n')
> +        self.transport.write(str(line) + '\r\n')
> 
> 
>      def _formatOneListResponse(self, name, size, directory, permissions, hardlinks, modified, owner, group):
> 

Rather than implementing an hard-coded conversion at lower level of FTP
protocol implementation, you could write explicit unicode encoders to
bytestream before making a call to FTP API.

By doing so you can have an FTP protocol, that beside UTF could also
handle other encodings.

Cheers,

-- 
Adi Roiban





More information about the Twisted-Python mailing list