Python Xlib applications report 'Can't connect to display ":0": No protocol specified' if XAUTH authentication is needed
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
python-xlib (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
The python-xlib package does not appear to correctly use X11 cookies from $XAUTHORITY under Ubuntu 18.04 (and possibly others).
GNOME3 appears to store the cookies in /run/user/
This deficiency is typically masked by the presence of "si:localuser:" entries in the xhost table; however, it is sometimes necessary to use XAUTH rather than xhost (e.g., when using certain Tcl/Tk applications which insist on the xhost table being empty for secure communication through the X server).
To reproduce:
xhost -si:localuser:$USER
python -c 'from Xlib.display import Display; Display()'
This results in:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/
self.display = _BaseDisplay(
File "/home/
protocol_
File "/home/
raise error.DisplayCo
Xlib.error.
If the xauth entry is updated to include ":0", e.g., via
xauth add $DISPLAY $(xauth list $DISPLAY | cut -d: -f2- | tail -1)
then running "python -c 'from Xlib.display import Display; Display()'" succeeds.
python3-xlib appears to have the same deficiency.
ProblemType: Bug
DistroRelease: Ubuntu 18.04
Package: python-xlib 0.20-3
ProcVersionSign
Uname: Linux 4.15.0-108-generic x86_64
ApportVersion: 2.20.9-0ubuntu7.15
Architecture: amd64
CurrentDesktop: ubuntu:GNOME
Date: Fri Jun 26 11:28:32 2020
Dependencies: python-six 1.11.0-2
InstallationDate: Installed on 2018-07-31 (695 days ago)
InstallationMedia: Ubuntu 18.04.1 LTS "Bionic Beaver" - Release amd64 (20180725)
PackageArchitec
SourcePackage: python-xlib
UpgradeStatus: No upgrade log present (probably fresh install)
Please note that although the Python traceback I posted cited a user-installed (via pip) version of python-xlib, the same symptom does also occur with the Ubuntu-packaged version in /usr/lib/ python2. 7/dist- packages/ Xlib/.
It is possible that the actual bug is GDM failing to correctly populate the display number in the $XAUTHORITY file /run/user/ $UID/gdm/ Xauthority; this bug report presumes (without justification) that an empty display number in the Xauthority file has a valid interpretation, but that python-xlib is not applying it. I note that other X applications (e.g., xclock) still work with "si:localuser: $USER" removed from the xhost list; I have only observed the failing behaviour with python-xlib and python3-xlib.