Archived Forum Post

Index of archived forum posts

Question:

Python: UnicodeDecodeError: 'utf-8' codec can't decode byte

Feb 27 '14 at 10:15

I'm trying SFTP Read Directory Listing(Python) of your example code.
http://www.example-code.com/python/sftp_readDir.asp
Here's the error message.

Traceback (most recent call last):
  File "C:/Users/chilkat/workspace/PythonTest/test.py", line 103, in <module>
    print(fileObj.filename())
  File "C:/Python33/lib/site-packages/chilkat.py", line 5601, in filename
46 files~!!
    def filename(self): return _chilkat.CkSFtpFile_filename(self)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb4 in position 0: invalid start byte
I'm using python33 and eclipse on MS Windows. Please let me know how to fix this problem.


Answer

The "Utf8" property can be set to True to indicate that Chilkat should return utf-8 strings, and also interpret input string arguments as utf-8. (When Utf8 is False, which is the default, then ANSI strings are expected and returned by the Chilkat API.)

For example:

# indicate that input/output strings should be utf-8
sftp.put_Utf8(True)