I am trying to upload an XML with unicode content to a FTP server using ftplib, but getting the following exception when I try to upload the using storbinary method. The XML data is properly encoded to unicode (utf-8), I have made sure of that, I am not sure as to why storbinary is trying to encode it to 'ascii' while uploading. Can anyone please help?
--> 429 ftp.storbinary("STOR file.xml", xml) 430 431 def run(self): /usr/lib/python2.7/ftplib.pyc in storbinary(self, cmd, fp, blocksize, callback, rest) 463 buf = fp.read(blocksize) 464 if not buf: break --> 465 conn.sendall(buf) 466 if callback: callback(buf) 467 conn.close() /usr/lib/python2.7/socket.pyc in meth(name, self, *args) 222 223 def meth(name,self,*args): --> 224 return getattr(self._sock,name)(*args) 225 226 for _m in _socketmethods: UnicodeEncodeError: 'ascii' codec can't encode character u'\xae' in position 3368: ordinal not in range(128)
unicode
object, so it's not encoded at all. – Cairnarvonxml
a file object? If not, useStringIO
to create a file-like object from your xml string. – Austin Phillips