jbaiter / zotero-cli

Command-line interface for Zotero
MIT License
274 stars 41 forks source link

UnicodeEncodeError: 'latin-1' codec can't encode character #50

Open alopezespino opened 3 years ago

alopezespino commented 3 years ago

I had this issue, and I'm posting the solution here in case someone has the same problem.

After configuring zotcli, I did my first query and got the following error.

Traceback (most recent call last): File "/Users/ale/miniconda3/bin/zotcli", line 8, in <module> sys.exit(cli()) File "/Users/ale/miniconda3/lib/python3.8/site-packages/click/core.py", line 1137, in __call__ return self.main(*args, **kwargs) File "/Users/ale/miniconda3/lib/python3.8/site-packages/click/core.py", line 1062, in main rv = self.invoke(ctx) File "/Users/ale/miniconda3/lib/python3.8/site-packages/click/core.py", line 1668, in invoke return _process_result(sub_ctx.command.invoke(sub_ctx)) File "/Users/ale/miniconda3/lib/python3.8/site-packages/click/core.py", line 1404, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/ale/miniconda3/lib/python3.8/site-packages/click/core.py", line 763, in invoke return __callback(*args, **kwargs) File "/Users/ale/miniconda3/lib/python3.8/site-packages/click/decorators.py", line 26, in new_func return f(get_current_context(), *args, **kwargs) File "/Users/ale/miniconda3/lib/python3.8/site-packages/zotero_cli/cli.py", line 183, in query click.echo(out) File "/Users/ale/miniconda3/lib/python3.8/site-packages/click/utils.py", line 298, in echo file.write(out) # type: ignore UnicodeEncodeError: 'latin-1' codec can't encode character '\ufb01' in position 28: ordinal not in range(256)

This is a python issue with special characters in Zotero references that clash with my default python encoding.

I fixed this by changing the following environment variable:

export PYTHONIOENCODING=utf8

I hope it helps others that come across the same issue!