cwoac / TTS-Manager

Import/Export Mods from Tabletop Simulator
MIT License
23 stars 10 forks source link

Character encoding error #14

Closed javi-dev closed 9 years ago

javi-dev commented 9 years ago

Hi, I'm getting this when I try to run the GUI.

Traceback (most recent call last):
File "tts_gui.py", line 289, in <module>
File "tts_gui.py", line 285, in main
File "tts_gui.py", line 255, in __init__
File "tts_gui.py", line 104, in populate_list_frame
File "tts_gui.py", line 54, in list_command
File "C:\Users\mattheol\Documents\GitHub\TTS-Manager\tts\tts.py", line 42, in describe_files_by_type
File "C:\Users\mattheol\Documents\GitHub\TTS-Manager\tts\tts.py", line 37, in load_file_by_type
File "C:\Users\mattheol\Documents\GitHub\TTS-Manager\tts\tts.py", line 31, in load_json_file
File "C:\Python34\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 841: character maps to <undefined>

Some info: I'm running Windows 8.1 (Spanish version). I used the installer and I'm running the GUI version. I have Python 3 installed on my system, as you can see in the log.

I'm not a Python developer, but I've been looking around and I believe this stackoverflow question may help.

I have a lot of downloaded Workshop files, but I can move them out of the folder, and try to isolate the problem if it helps.

Thanks!

EDIT: Same error with tts_cli list.

javi-dev commented 9 years ago

Ok, so picture the "I have no idea what I'm doing" dog, and you'll have an idea of me using Python.

I cloned this repo, and ran tts_gui.py using the Python installed in my system (python.exe tts_gui.py), which gave me more detailed info:

Traceback (most recent call last):
  File "tts_gui.py", line 289, in <module>
    main()
  File "tts_gui.py", line 285, in main
    tts_gui=TTS_GUI(root)
  File "tts_gui.py", line 255, in __init__
    self.populate_list_frame(list_frame)
  File "tts_gui.py", line 104, in populate_list_frame
    self.list_sb.list_command()
  File "tts_gui.py", line 54, in list_command
    data=tts.describe_files_by_type(self.filesystem,self.save_type.get())
  File "C:\Users\live_000\Desktop\tts-manager\TTS-Manager\tts\tts.py", line 42, in describe_files_by_type
    json=load_file_by_type(filename,filesystem,save_type)
  File "C:\Users\live_000\Desktop\tts-manager\TTS-Manager\tts\tts.py", line 37, in load_file_by_type
    return load_json_file(filename)
  File "C:\Users\live_000\Desktop\tts-manager\TTS-Manager\tts\tts.py", line 31, in load_json_file
    data=open(filename,'r').read()
  File "c:\Python34\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x9d in position 841: character maps to <undefined>

Now, that line 31 looked interesting, and after Googling around, found another so answer, imported the codecs module at the top of the file, and changed line 31 to look like this:

data=codecs.open(filename,'r', 'utf-8').read()

And now the GUI opens and it lists all my Workshop, Save and Chest files, and the tts_cli list command works as well. But as I said, I have no idea if what I did is correct, or if it's going to blow up in another place, so I leave it up to you. Hope it helps.

cwoac commented 9 years ago

That's approximately the solution I was looking at, my concern is that I believe NTFS uses utf-16 natively, so that may not fix it for arabic / chinese users.

cwoac commented 9 years ago

I went with a slightly different approach that will fall back if utf-8 fails. Hopefully 3ab109bd8071390d2b443fbc569983e10f2ec00c resolves this.

javi-dev commented 9 years ago

Thanks, it's working now, at least for me. The GUI opens, and the CLI lists my files.