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

Run Python script as Programs dictionary return about UnicodeEncodeError. #1678

Closed
scillidan opened this issue Nov 12, 2023 · 4 comments
Closed

Comments

@scillidan
Copy link

OS: Windows 10
Version: GoldenDict 1.5.0 (Protable)

I add ety-python into Programs of GoldenDict as dictionary. It's data come from .tsv of http://etym.org/.

The command line is ety -r -t "%GDWORD%", it return some errors when I search some word liked apple, aerodynamically:

Query error: The program has returned exit code 1. Traceback (most recent call last): File "\\?\C:\Users\scillidan\scoop\persist\python39\Scripts\ety-script.py", line 33, in <module> sys.exit(load_entry_point('ety==1.4.0', 'console_scripts', 'ety')()) File "C:\Users\scillidan\scoop\apps\python39\current\lib\site-packages\ety-1.4.0-py3.9.egg\ety\cli.py", line 42, in cli print(output.strip()) UnicodeEncodeError: 'gbk' codec can't encode character '\u1f00' in position 112: illegal multibyte sequence

I try it in cmd.exe, ety -r -t aerodynamically return:

aerodynamically (English)
├── -ally (English)
└── aerodynamic (English)
    ├── aero- (English)
    │   └── ἀήρ (Ancient Greek (to 1453))
    └── dynamic (English)
        └── dynamique (French)
            └── δυναμικός (Ancient Greek (to 1453))
                └── δύναμις (Ancient Greek (to 1453))
                    └── δύναμαι (Ancient Greek (to 1453))

I have similar problems when I used other python cli liked etym-cli in GoldenDict🤔. And node cli thes work well.

@wildekat
Copy link

Your version of Python seems to be set up to automatically convert things to GBK on output:

$ PYTHONIOENCODING=GBK python3 -c "print('ἀ')"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
UnicodeEncodeError: 'gbk' codec can't encode character '\u1f00' in position 0: illegal multibyte sequence

However, I don't see how that could be GoldenDict's fault - there's just no way GD would ever set PYTHONIOENCODING or any of its equivalents.
When in cmd.exe, does ety still work when redirected to a file: ety -r -t aerodynamically >test_redir ??

@scillidan
Copy link
Author

I got the same output in cmd.exe with python39 and python310.

D:\home>ety.exe -r -t aerodynamically >test_redir
Traceback (most recent call last):
  File "\\?\C:\Users\scillidan\scoop\persist\python39\Scripts\ety-script.py", line 33, in <module>
    sys.exit(load_entry_point('ety', 'console_scripts', 'ety')())
  File "d:\cacher\goldendict_ety-python\ety\cli.py", line 42, in cli
    print(output.strip())
UnicodeEncodeError: 'gbk' codec can't encode character '\u1f00' in position 112: illegal multibyte sequence

I checked my environment, and I didn't seem to set any environment values except for where python.exe and Scripts/ are.

I should test it on wsl2 later, but I uninstalled it before and need to reinstall it.

@scillidan
Copy link
Author

scillidan commented Nov 21, 2023

I test it on wsl2. It works well on them.

image

image

image

And get same errors on newly installed Windows10 in VirtualBox, when redirected to a file:

image

So weird.

@scillidan
Copy link
Author

scillidan commented Nov 26, 2023

It's not a GoldenDict's problem, which prevents me from wasting more time in the wrong direction.
Thanks for GPT-3.5's help!
For my purposes only, the problem is solved.

image

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