So, I am a human/programmer. But this bug/report was found/written by ChatGPT. What ChatGPT did fixed my issue so my current understanding is it is legitimate. But, its somewhat over my head. You have my sincere apology for wasting your time if this is actually bogus.
Environment
- Ubuntu 26.04 LTS
- Wayland session with XWayland
- Python 3.14.x
- python-xlib 0.33
DISPLAY=:0
- Xauthority file provided by Mutter/XWayland via
$XAUTHORITY
Description
python-xlib is unable to connect to the local XWayland display because new_get_auth() does not find the authentication entry in the Xauthority file.
The Xauthority file contains entries whose display-number field is empty:
family=256 addr=<hostname> num=b''
family=65535 addr=<hostname> num=b''
However, unix_connect.new_get_auth() ultimately calls Xauthority.get_best_auth() with display number 0, which is converted to b'0'. Consequently, the entries with num=b'' are not matched and new_get_auth() returns empty authentication credentials.
The result is:
Xlib.error.DisplayConnectionError:
Can't connect to display ":0":
b'Authorization required, but no authorization protocol specified'
Reproduction
With the normal environment:
echo $XDG_SESSION_TYPE
# wayland
echo $DISPLAY
# :0
echo $XAUTHORITY
# /run/user/1000/.mutter-Xwaylandauth.<...>
This fails:
python3 -c "from Xlib import display; d=display.Display(); print(d.get_display_name())"
with an authorization error.
The Xauthority file can be parsed successfully with Xlib.xauth, but its entries have an empty display-number field.
Interestingly, other X clients work correctly. For example:
works, and:
python3 -c "import tkinter; r=tkinter.Tk(); print('X connection works'); r.destroy()"
also works.
The Unix X socket itself is accessible:
Additional observation
The old xauth-based authentication path is able to locate the cookie:
returns the correct MIT-MAGIC-COOKIE-1 cookie, but the implementation in that path converts the hexadecimal cookie to a Python str rather than raw bytes. Using bytes.fromhex() instead allows the Xlib connection to succeed:
auth_name = parts[1].encode()
auth_data = bytes.fromhex(parts[2])
return auth_name, auth_data
With that modification, this succeeds:
from Xlib import display
d = display.Display()
print(d.get_display_name())
and prints:
Relevance to 0.32
The 0.32 changelog says:
Fix for auth entry having no display number
This appears closely related to the problem described above, but the problem is still reproducible with python-xlib 0.33 on this system.
I am therefore wondering whether this is an unhandled variant of the no-display-number case, or whether the 0.32 fix does not apply to Xauthority files generated by Mutter/XWayland.
The actual Xauthority cookie is omitted from this report.
So, I am a human/programmer. But this bug/report was found/written by ChatGPT. What ChatGPT did fixed my issue so my current understanding is it is legitimate. But, its somewhat over my head. You have my sincere apology for wasting your time if this is actually bogus.
Environment
DISPLAY=:0$XAUTHORITYDescription
python-xlibis unable to connect to the local XWayland display becausenew_get_auth()does not find the authentication entry in the Xauthority file.The Xauthority file contains entries whose display-number field is empty:
However,
unix_connect.new_get_auth()ultimately callsXauthority.get_best_auth()with display number0, which is converted tob'0'. Consequently, the entries withnum=b''are not matched andnew_get_auth()returns empty authentication credentials.The result is:
Reproduction
With the normal environment:
This fails:
python3 -c "from Xlib import display; d=display.Display(); print(d.get_display_name())"with an authorization error.
The Xauthority file can be parsed successfully with
Xlib.xauth, but its entries have an empty display-number field.Interestingly, other X clients work correctly. For example:
works, and:
python3 -c "import tkinter; r=tkinter.Tk(); print('X connection works'); r.destroy()"also works.
The Unix X socket itself is accessible:
Additional observation
The old
xauth-based authentication path is able to locate the cookie:old_get_auth(...)returns the correct
MIT-MAGIC-COOKIE-1cookie, but the implementation in that path converts the hexadecimal cookie to a Pythonstrrather than raw bytes. Usingbytes.fromhex()instead allows the Xlib connection to succeed:With that modification, this succeeds:
and prints:
Relevance to 0.32
The 0.32 changelog says:
This appears closely related to the problem described above, but the problem is still reproducible with python-xlib 0.33 on this system.
I am therefore wondering whether this is an unhandled variant of the no-display-number case, or whether the 0.32 fix does not apply to Xauthority files generated by Mutter/XWayland.
The actual Xauthority cookie is omitted from this report.