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

Support directories with unicode chars #13

Open
canepan opened this issue Apr 29, 2021 · 2 comments
Open

Support directories with unicode chars #13

canepan opened this issue Apr 29, 2021 · 2 comments

Comments

@canepan
Copy link

canepan commented Apr 29, 2021

Hi, I stumbled upon this issue while using duviz on my disk with an accentuated letter ("é").
The error was:

   File "/usr/local/bin/duviz.py", line 72, in from_path_size_pairs
    for path, size in pairs:
  File "/usr/local/bin/duviz.py", line 130, in pairs
    progress_report(path)
  File "/usr/local/bin/duviz.py", line 453, in progress
    write(info.ljust(terminal_width)[:terminal_width] + '\r')
UnicodeEncodeError: 'ascii' codec can't encode character '\u2014' in position 138: ordinal not in range(128)

and according to this article it can be resolved by adding (the one which worked for me):

    os.environ["PYTHONIOENCODING"] = "utf-8"

at the beginning of main()

Nicola

canepan added a commit to canepan/duviz that referenced this issue Apr 30, 2021
@soxofaan
Copy link
Owner

I don't completely understand: the exception talks about character '\u2014' which is "EM DASH", not accented "é"

I'm also not sure about setting os.environ["PYTHONIOENCODING"] from within the script. It doesn't seem good style to blindly set an env variable in a script, I think this should be set properly in the shell. Moreover, if I understand the docs https://docs.python.org/3/using/cmdline.html#envvar-PYTHONIOENCODING correctly, setting it inside the script (so not "before running the interpreter") will not be effective in the first place.

@canepan
Copy link
Author

canepan commented Nov 9, 2022

It has been effective for me, but it may change with newer versions.
To stay on the safe side, but still avoid failing, I see 2 options:

  • wrap the duviz.py invocation in a shell script to be added to the repo (and a .cmd if needed)
  • do a try/except and possibly (since it's just dealing with the transient progress display) ignore the line

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