When moving files using the shutill module: shutill.move(path1,path2) this error:

  Traceback (most recent call last): File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__ return self.func(*args) File "cleaner.py", line 88, in moveF moveFiles(pathdir,videos,"vid", dirnames) File "cleaner.py", line 70, in moveFiles shutil.move(path+file1, pathe3+file1) UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 4: ordinal not in range(128) 

The paths are taken using Tkinter, tkFileDialog, and files through os.listdir I tried to use path1.decode("utf-8") and path2.decode("utf-8") result is the same. (

1 answer 1

The error has nothing to do with shutil.move() . No need to mix Unicode strings and bytes:

 >>> u"a" + "ф" Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeDecodeError: 'ascii' codec can't decode byte 0xd1 in position 0: ordinal not in range(128) 

.encode() , .decode() to the blind in the hope that this will correct the errors associated with the encoding should also not be. Instead, you should clearly understand whether you are working with bytes ( type(b) == str on Python 2) or with Unicode ( type(u) == unicode ).

If the environment (locale) is properly configured:

 >>> import sys >>> sys.getfilesystemencoding() 'UTF-8' 

and there are no problems with unrepresentable names , use Unicode for file names. Never mix Unicode and bytes - explicitly convert one into the other if necessary. See details in How to work with paths with Russian characters?