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

Error while backup favorites #39

Closed
BigDi opened this issue Jul 2, 2024 · 4 comments
Closed

Error while backup favorites #39

BigDi opened this issue Jul 2, 2024 · 4 comments

Comments

@BigDi
Copy link

BigDi commented Jul 2, 2024

Get a traceback while backuping my 1086 favorites.

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ C:\Python311\Lib\site-packages\kptncook_init_.py:167 in backup_kptncook_favorites │
│ │
│ 164 │ │ sys.exit(1) │
│ 165 │ │
│ 166 │ fs_repo = RecipeRepository(settings.root) │
│ ❱ 167 │ fs_repo.add_list(recipes) │
│ 168 │ rprint(f"Added {len(recipes)} recipes to local repository") │
│ 169 │
│ 170 │

UnicodeEncodeError: 'charmap' codec can't encode character '\u202f' in position 829203: character maps to

@Kadz93
Copy link

Kadz93 commented Aug 21, 2024

super quick fix, i hope somebody sees it lol @ephes @alexdetsch @luebbert42

in repository.py add utf8 encodings in the functions:

  • _write_models -> line 60
  • _fetch_all -> line 70

you can do it in your local code @BigDi

@ephes
Copy link
Owner

ephes commented Sep 13, 2024

Well, pydantic deliberately returns a unicode string when models.model_dump_json() is called. And calling write on a file opened in text mode should do the right thing on your operating system. Maybe your default encoding is something like cp1252?

Hmm, maybe it's enough just to overwrite the operating system default by calling:

        with self.path.open("w", encoding="utf-8") as f:
            f.write(models.model_dump_json())

This is still normal text mode, but would overwrite the default encoding and use utf-8. Can you try this and tell me if it works on windows?

@Kadz93
Copy link

Kadz93 commented Sep 13, 2024

I can confirm that the additional encoding solves the problem on windows.

@ephes
Copy link
Owner

ephes commented Sep 16, 2024

Cool! I'll released 0.0.21 containing the fix.

@ephes ephes closed this as completed Sep 16, 2024
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

3 participants