paulbricman / dual-obsidian-client

A skilled virtual assistant for Obsidian.
https://paulbricman.com/thoughtware/dual
Mozilla Public License 2.0
242 stars 7 forks source link

UnicodeDecodeError in utils.py when running server.py #57

Closed jadenaccord closed 3 years ago

jadenaccord commented 3 years ago

(Python 3.8.4 on Windows 10 20H2 (64 bit))

When I ran "python server.py --path /path/to/vault" inside my vault directory, I received the following output:

Loading skeleton... Loading essence... Cache file doesn't exist, creating a new one... Traceback (most recent call last): File "server.py", line 12, in cw = ConversationalWrapper(args.path) File "C:\Users\jaden\OneDrive\Documents\Obsidian\obsidian-vault.obsidian\plugins\Dual\skeleton\conversational_wrapper.py", line 7, in init self.core = Core(root_dir) File "C:\Users\jaden\OneDrive\Documents\Obsidian\obsidian-vault.obsidian\plugins\Dual\skeleton\core.py", line 25, in init self.create_cache() File "C:\Users\jaden\OneDrive\Documents\Obsidian\obsidian-vault.obsidian\plugins\Dual\skeleton\core.py", line 135, in create_cache self.entry_contents = [md_to_text( File "C:\Users\jaden\OneDrive\Documents\Obsidian\obsidian-vault.obsidian\plugins\Dual\skeleton\core.py", line 135, in self.entry_contents = [md_to_text( File "C:\Users\jaden\OneDrive\Documents\Obsidian\obsidian-vault.obsidian\plugins\Dual\skeleton\util.py", line 8, in md_to_text content = open(file).read() File "C:\Users\jaden\AppData\Local\Programs\Python\Python38\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 0x8f in position 4: character maps to

A quick Google search got me to this StackOverflow question: https://stackoverflow.com/questions/9233027/unicodedecodeerror-charmap-codec-cant-decode-byte-x-in-position-y-character.

One person suggested specifying the encoding when opening the file. So, inside skeleton/util.py, I changed content = open(file).read() (line 8) to content = open(file, "utf8").read() and this solved the problem. But I thought it was worth mentioning anyway as I didn't see anything in the documentation about file encoding.

Doom666 commented 3 years ago

I did and although it went over the skeleton, when loading the essence, it showed this: Loading skeleton... Loading essence... Downloading: 100%|████████████████████████████████████████████████████████████████| 1.04M/1.04M [00:00<00:00, 2.33MB/s] Downloading: 100%|██████████████████████████████████████████████████████████████████| 456k/456k [00:00<00:00, 1.43MB/s] Downloading: 100%|████████████████████████████████████████████████████████████████| 1.36M/1.36M [00:00<00:00, 2.74MB/s] Cache file doesn't exist, creating a new one... Traceback (most recent call last): File "C:\Users\Eier\Documents\ObsidianVaults\Matrix.obsidian\plugins\Dual\skeleton\server.py", line 12, in cw = ConversationalWrapper(args.path) File "C:\Users\Eier\Documents\ObsidianVaults\Matrix.obsidian\plugins\Dual\skeleton\conversational_wrapper.py", line 7, in init self.core = Core(root_dir) File "C:\Users\Eier\Documents\ObsidianVaults\Matrix.obsidian\plugins\Dual\skeleton\core.py", line 25, in init self.create_cache() File "C:\Users\Eier\Documents\ObsidianVaults\Matrix.obsidian\plugins\Dual\skeleton\core.py", line 135, in create_cache self.entry_contents = [md_to_text( File "C:\Users\Eier\Documents\ObsidianVaults\Matrix.obsidian\plugins\Dual\skeleton\core.py", line 135, in self.entry_contents = [md_to_text( File "C:\Users\Eier\Documents\ObsidianVaults\Matrix.obsidian\plugins\Dual\skeleton\util.py", line 8, in md_to_text content = open(file, "utf8").read() ValueError: invalid mode: 'utf8'

jadenaccord commented 3 years ago

What OS are you on?

paulbricman commented 3 years ago

Closing this because the new Rust backend makes issues related to the old Python backend irrelevant.