-
Notifications
You must be signed in to change notification settings - Fork 54
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
Encoding issues #183
Comments
Looks fine for me... But it should be |
was fixed by #184 |
I am concerned we are introducing a problem for people. If the console doesn't support UTF-8, we shouldn't force it. I think the correct option is to configure the terminal correctly. One way to avoid error would be to use A better way to avoid error is to use unidecode to replace undisplayable unicode characters with similar ascii characters. |
Like pointing this out for users in the README?
Using
This should be more elegant but I think we must try to use "utf-8" before that too. |
@arturgontijo I think we should try to print utf-8 encoding by default, but in the exception handling choose one of:
A complete solution would be to inspect the terminal environment to decide the correct encoding, but I'm not sure how easy/complex those settings are to get right. |
yes. It seems we hurried with the decision. I would vote for the following solution: Intercept "UnicodeEncodeError" and do the following:
|
What will happen if we force utf-8 characters on terminal which do not support utf-8? Maybe it was not a bad decision after all? We could force utf-8 but print a warning.. |
I still think that we must "force" the Console 1 (does support utf-8 but it is not set)
I'm kind of lost here, because I can't figure out how to simulate it. |
I imagine that you'd get some unexpected characters or junk. But I'm unsure. I was thinking of something like: utf8_warning_printed = False
@staticmethod
def _print(message, fd):
try:
fd.buffer.write(str(message).encode("utf-8") + "\n")
except UnicodeEncodeError:
if not utf8_warning_printed:
fd.buffer.write("Error attempting to encode unicode! Please ensure your locale supports UTF-8 if you want to see correct character representations.")
utf8_warning_printed = True
fd.write(str(message).encode("ascii", "ignore") + "\n") For "Console 1 (does support utf-8 but it is not set)" - I'm pretty sure we can't detect or fix this if the user has the wrong setting. So I think we should just warn them... If we start trying to be clever I think we'll make things much harder to debug for ourselves (and for our users trying to configure things!). |
Ok, I think I've got the idea.
I'm not using About the warning, maybe we can show: |
If I run
snet
in a Docker container I get an encoding error:I can set
locale
in Dockerfile and also force it within python:I'd like to suggest an
UnicodeEncodeError
handler.One approach is using
stdout.buffer
, with itsnet
will become console's encoding independent.Example commands.py#L39:
The text was updated successfully, but these errors were encountered: