My code is
file_size = os.path.getsize(file_path)
I get the following exception when Unicode characters present in the file_path
File "C:\Python27\lib\genericpath.py", line 57, in getsize
return os.stat(filename).st_size
WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 'E:\\Backup\\MyFolder\\~$??????.docx'
NOTE: I don't get the same error when I run the same code via Python 3.
My question is how to fix the code to run on both Python 2 and 3?