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

Start genie but throw a Python error: "UnicodeEncodeError" #268

Closed
1 task done
WhiteByeBye opened this issue May 6, 2022 · 8 comments
Closed
1 task done

Start genie but throw a Python error: "UnicodeEncodeError" #268

WhiteByeBye opened this issue May 6, 2022 · 8 comments
Assignees
Labels
bug Something isn't working

Comments

@WhiteByeBye
Copy link

Windows version (build number):
Windows 11 Dev Channel build 22616.1 (the latest one)

Linux distribution:
Ubuntu

Kernel version:
5.10.102.1-microsoft-standard-WSL2

Genie version:
genie 2.3

Describe the bug
When I use the command "genie -s" to start it, it throws a python error:


genie: WARNING: systemd default target is default.target; targets other than multi-user.target may not work
genie: WARNING: if you wish to use a different target, this warning can be disabled in the config file
genie: WARNING: if you experience problems, please change the target to multi-user.target
Traceback (most recent call last):
File "/home/{my_username}/anaconda3/lib/python3.9/runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/home/{my_username}/anaconda3/lib/python3.9/runpy.py", line 87, in _run_code
exec(code, run_globals)
File "/usr/lib/genie/genie/main.py", line 904, in
File "/usr/lib/genie/genie/main.py", line 887, in entrypoint
File "/usr/lib/genie/genie/main.py", line 590, in do_initialize
File "/usr/lib/genie/genie/main.py", line 229, in hostname_update
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 0-1: surrogates not allowed
could not initialise bottle, exit code = 1


Confirm that you are running inside the bottle:
no-bottle

I confirm that I have read the ENTIRE supplied readme file and checked for relevant information on the repository wiki before raising this issue, and that if the solution to this issue is found in either location, it will be closed without further comment:

  • Yes.
@WhiteByeBye WhiteByeBye added the bug Something isn't working label May 6, 2022
@cerebrate
Copy link
Member

That's an odd one. What is the hostname of your machine?

@WhiteByeBye
Copy link
Author

I gave my computer a Chinese name called "机械革命." So, should my machine's hostname be in English?

@cerebrate
Copy link
Member

I'm wasn't totally sure about this. I started out assuming that Unicode would be acceptable in hostnames, but when I tried to set your hostname (or other non-ASCII hostnames) with the hostname(1) or hostnamectl(1) commands, they both rejected it:

❯ sudo hostname 机械革命
hostname: the specified hostname is invalid
[1]    328332 exit 1     sudo hostname 机械革命

❯ sudo hostnamectl hostname --static 机械革命
Could not set static hostname: Invalid static hostname '机械革命'
[1]    328629 exit 1     sudo hostnamectl hostname --static 机械革命

And then when I looked it up, it seems that Unicode isn't allowed:

Each element of the hostname must be from 1 to 63 characters long
and the entire hostname, including the dots, can be at most 253
characters long. Valid characters for hostnames are ASCII(7)
letters from a to z, the digits from 0 to 9, and the hyphen (-).
A hostname may not start with a hyphen.

So from that, it looks like only English (and a limited subset of English, at that) hostnames are allowed. There is a way to encode other character sets into hostnames for DNS purposes, Punycode, but while that translates 机械革命 into xn--ltrx94bc6a885i and back again, using the latter as a hostname in Linux appears on screen, etc., as xn--ltrx94bc6a885i; it seems to be only web browsers and such that translate it into the proper characters for display.

I'll see what I can do to fix the Unicode error anyway, but I suspect there are probably more problems down the road trying to use a non-ASCII hostname, at least for now. Sorry.

@WhiteByeBye
Copy link
Author

'机械革命' is the hostname of my Windows OS. Because Windows allows Chinese hostnames. So maybe WSL inherited its hostname. I will try to change the hostname to English, observe if there are any problems, and then give feedback again.

I appreciate your efforts to fix the problem, and it would be great if Chinese hostnames were allowed in later versions!

@WhiteByeBye
Copy link
Author

I have changed my hostname to English, and now everything seems normal. So the problem is indeed the Chinese hostname.

Thanks for your help! If fixing this problem is too complicated, you could close the issue. But I still expect that if possible, Genie can support the Chinese hostname in the future release!

@cerebrate
Copy link
Member

I checked into the Windows side of this too ( https://docs.microsoft.com/en-us/troubleshoot/windows-server/identity/naming-conventions-for-computer-domain-site-ou#dns-host-names ), which apparently boils down to Windows supports Unicode hostnames, as does the Microsoft DNS server that ships with Windows Server, but they acknowledge that non-Microsoft implementations of DNS, etc., don't support Unicode and so they should be avoided if they're going to travel outside a pure-Microsoft system.

Unfortunately, given that the underlying problem seems embedded into Linux (and Internet standards in general, per RFC952 / RFC 1123) I don't think it's something that can be fixed just in genie. I'd like to leave this open for a while, though, both so I can put better error-handling in genie, and so that I can raise this issue with the WSL team so that other people don't run into this same issue in future.

@cerebrate
Copy link
Member

On another note, you can configure a separate hostname for a WSL distro by adding some lines in the /etc/wsl.conf file:

[network]
hostname = wslhostname

...so that might offer an alternative which fixes the WSL hostname issue without needing you to change the Chinese hostname of the Windows machine.

@cerebrate
Copy link
Member

Better error-handling and warning message now added to genie. Now just waiting on the underlying WSL fix, so closing this in favor of microsoft/WSL#8386.

@cerebrate cerebrate unpinned this issue Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants