Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unicode Encode Error #4

Open
MHee opened this issue Oct 30, 2023 · 1 comment
Open

Unicode Encode Error #4

MHee opened this issue Oct 30, 2023 · 1 comment

Comments

@MHee
Copy link

MHee commented Oct 30, 2023

I got encoding errors when importing my highlights:

(kobo) C:\Users\mheesema>kh import
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Data\miniconda3\envs\kobo\Scripts\kh.exe\__main__.py", line 7, in <module>
  File "C:\Data\miniconda3\envs\kobo\Lib\site-packages\typer\main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Data\miniconda3\envs\kobo\Lib\site-packages\click\core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Data\miniconda3\envs\kobo\Lib\site-packages\click\core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "C:\Data\miniconda3\envs\kobo\Lib\site-packages\click\core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Data\miniconda3\envs\kobo\Lib\site-packages\click\core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Data\miniconda3\envs\kobo\Lib\site-packages\click\core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Data\miniconda3\envs\kobo\Lib\site-packages\typer\main.py", line 532, in wrapper
    return callback(**use_params)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Data\miniconda3\envs\kobo\Lib\site-packages\kobo_highlights\main.py", line 152, in import_highlights
    add_bookmark_to_md(bookmark, config.target_dir)
  File "C:\Data\miniconda3\envs\kobo\Lib\site-packages\kobo_highlights\functions.py", line 290, in add_bookmark_to_md
    md_filepath.write_text(text_new_file)
  File "C:\Data\miniconda3\envs\kobo\Lib\pathlib.py", line 1079, in write_text
    return f.write(data)
           ^^^^^^^^^^^^^
  File "C:\Data\miniconda3\envs\kobo\Lib\encodings\cp1252.py", line 19, in encode
    return codecs.charmap_encode(input,self.errors,encoding_table)[0]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
UnicodeEncodeError: 'charmap' codec can't encode character '\u0101' in position 42: character maps to <undefined>

Adding UTF-8 encoding to lines 286 and 290 in functions.py solved the problem for me:

    if md_filepath.is_file():
        with md_filepath.open("a", encoding='utf-8') as md_file:
            md_file.write(text_existing_file)

    else:
        md_filepath.write_text(text_new_file, encoding='utf-8')
@videbar
Copy link
Owner

videbar commented Nov 2, 2023

Thanks for the suggestions, I've just published a new version including them. Please let me know if the new version works for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants