ObsidianToAnki / Obsidian_to_Anki

Script to add flashcards from text/markdown files to Anki
GNU General Public License v3.0
1.56k stars 137 forks source link

'utf-8' error #100

Closed raphaelhuleux closed 3 years ago

raphaelhuleux commented 4 years ago

Hello,

When I try to update my notes to Anki, I get this new error. I'm not sure what causes it, I checked the titles of my notes and they don't have anything too weird.

Regards,

Traceback (most recent call last):
  File "/Users/raphaelhuleux/Documents/Projects/markdown_scripts/obisidan_to_anki/obsidian_to_anki.py", line 1561, in <module>
    main()
  File "/Users/raphaelhuleux/Documents/Projects/markdown_scripts/obisidan_to_anki/obsidian_to_anki.py", line 187, in main
    App()
  File "/Users/raphaelhuleux/Documents/Projects/markdown_scripts/obisidan_to_anki/obsidian_to_anki.py", line 880, in __init__
    Directory(
  File "/Users/raphaelhuleux/Documents/Projects/markdown_scripts/obisidan_to_anki/obsidian_to_anki.py", line 1430, in __init__
    [
  File "/Users/raphaelhuleux/Documents/Projects/markdown_scripts/obisidan_to_anki/obsidian_to_anki.py", line 1431, in <listcomp>
    self.file_class(entry.path)
  File "/Users/raphaelhuleux/Documents/Projects/markdown_scripts/obisidan_to_anki/obsidian_to_anki.py", line 1109, in __init__
    self.file = f.read()
  File "/Users/raphaelhuleux/opt/anaconda3/lib/python3.8/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa1 in position 440: invalid start byte
Pseudonium commented 3 years ago

Should hopefully be fixed in the newest release! Many people have been reporting this issue. Do let me know if it persists though.

tedblizzard100 commented 3 years ago

@Pseudonium Seems there might still be an issue. but happy to apply any advice you have. Thank you for your work on this.

Traceback (most recent call last): File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1707, in main() File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 206, in main App() File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 897, in init Directory(root, regex=args.regex) File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1578, in init for entry in it File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1581, in )[1] in App.SUPPORTED_EXTS File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1173, in init self.file = f.read() File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xae in position 83: invalid start byte

Pseudonium commented 3 years ago

Right, could you send me the problematic file?

tedblizzard100 commented 3 years ago

Writing Reference ID.md attached. ... Identified target deck for .\Writing Reference ID.md as Default Traceback (most recent call last): ...

Writing Reference ID.zip

Pseudonium commented 3 years ago

Strange, the version of the script I'm running doesn't encounter an error when reading this file...

tedblizzard100 commented 3 years ago

Yes, very strange. individual files process but it is when I run the entire directory that the error happens. If there is anything else, I can do to help identify the issue, please let me know. Thank you.

This is what the end of the process looks like: Identified target deck for .\Wordie Test.md as Default Identified target deck for .\Workbench.md as Default Identified target deck for .\Writing Reference ID.md as Default Traceback (most recent call last): File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1707, in main() File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 206, in main App() File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 906, in init os.getcwd(), regex=args.regex File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1578, in init for entry in it File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1581, in )[1] in App.SUPPORTED_EXTS File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1173, in init self.file = f.read() File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xae in position 83: invalid start byte

tedblizzard100 commented 3 years ago

I also see that when I process individual files I get Anki cards and everything works. But when I process the directory, I don't get any cards inserted into Anki and no id's in Obsidian.

Pseudonium commented 3 years ago

That's very strange indeed that individual files process but the directory doesn't. Under the hood, neither should be that different - both instantiate the same file in the same way!

Pseudonium commented 3 years ago

And I still can't reproduce the error here, which makes it difficult to debug! I also tried running it over the directory, and that seems to work.

tedblizzard100 commented 3 years ago

This a screen cam to show you what it looks like: https://www.loom.com/share/85788bbbf82343debe46080cc7a7d922 Below is the error and I attached the INI in case I did something wrong in the config.

obsidian_to_anki_config.zip

Attempting to connect to Anki... Connected! Loading configuration file... Loaded successfully! Traceback (most recent call last): File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1748, in main() File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 217, in main App() File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 909, in init Directory(root, regex=args.regex) File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1604, in init for entry in it File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1607, in )[1] in App.SUPPORTED_EXTS File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1192, in init self.file = f.read() File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xae in position 83: invalid start byte

Pseudonium commented 3 years ago

One suggestion - if you use the new Obsidian plugin version of the script, this error probably won't occur? Since Obsidian takes care of reading the file.

tedblizzard100 commented 3 years ago

I changed to the plugin and refreshed all the code. The individual files work fine but the folder still giving me a problem.

Do you have any suggestions? Thank you.

Attempting to connect to Anki... Connected! Loading configuration file... Loaded successfully! Traceback (most recent call last): File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1778, in main() File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 217, in main App() File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 936, in init os.getcwd(), regex=args.regex File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1630, in init for entry in it File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1633, in )[1] in App.SUPPORTED_EXTS File "C:\Users\tedbl\OneDrive\Documents\B_Brain_V1\obsidian_to_anki.py", line 1210, in init self.file = f.read() File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\lib\codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors, final) UnicodeDecodeError: 'utf-8' codec can't decode byte 0xae in position 83: invalid start byte

Pseudonium commented 3 years ago

Oh, by “Obsidian plugin”, I mean Obsidian_to_Anki is also a community plugin! You should be able to install it just from Obsidian, no python required.

tedblizzard100 commented 3 years ago

Yes, I installed the plugin from Obsidian. Perhaps the documentation in the plugin is not clear about how to perform the sync between Obsidian to Anki. It seems like the document requires the users to run the external Obsidian_to_Anki.py on the command line. Is that correct or is there a control sync inside Obsidian that the plugin provides?

Pseudonium commented 3 years ago

Look for an Anki icon on your ribbon - the place where ‘Open graph view’ and other buttons are.

tedblizzard100 commented 3 years ago

Yes, thank you. I see that. When I process the library, it is not building the cards or processing the MD files. I am guessing I messed up the setup in some way. At this point, I am just starting with the basic cards and the RemNote format. But it is not adding the cards to Anki.

Snag_348edc5 Snag_349c2e7

Pseudonium commented 3 years ago

Hmm, not even any console logs? You might want to try clearing the caches.

tedblizzard100 commented 3 years ago

Thank you. Caches cleared and now itis working with the basic RemNote format. This is a game-changer for the way I take notes.

Now, I am on to testing the cloze, images, and audio.

Thank you!