How to fix error Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'No protocol specifiedn'
Question:
I’m making some program with python3 and XLib.
On my PC with Ubuntu 14.04 everything works fine but when I try to run my app in my notebook with manualy installed Xorg I get exception:
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'No protocol specifiedn'
on line:
self.__display = Xlib.display.Display()
What’s going on here? How to fix this that it could work on every Linux?
Edit:
This does not look like duplicate of X11: run a gnome app as another user. On my both computers I have same users and groups, so this problem is probably not connected with lack of permissions to run my program.
It must be something else something with bad configuration of X.
Answers:
Ok, It was bug in python3-xlib. See https://github.com/LiuLang/python3-xlib/issues/6 for details.
It definitely has something to do with the permissions.
To get super user permissions, on Linux you can simply type:
$ sudo su
<input your root password>
Now run the python file again
Hope this helped!
this problem is related to x display server connection policies, by default really restrictive
you can solve this issue by allowing access to the user that is going to be executing that code
if you’re the user that is going to execute plover then the code to be pasted in a shell is
xhost +local:$USER
otherwise you can switch out $USER
with the username of the user that’s going to run the code.
a way to make this change permanent is adding that line of code to your login script, id est ~/.profile
for your user, or for any user at file /etc/profile/
in case you want to suppress command output text you can redirect output to /dev/null
, making the whole command:
xhost +local:$USER > /dev/null
had faced this same issue while trying to run plover.
The permanent proper solution is to add the allowed hosts and users to /etc/Xn.hosts
where n stands for the display number (e.g. /etc/X0.hosts
).
The following content will allow all users for localhost (without trailing whitespaces):
local:
I’m making some program with python3 and XLib.
On my PC with Ubuntu 14.04 everything works fine but when I try to run my app in my notebook with manualy installed Xorg I get exception:
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'No protocol specifiedn'
on line:
self.__display = Xlib.display.Display()
What’s going on here? How to fix this that it could work on every Linux?
Edit:
This does not look like duplicate of X11: run a gnome app as another user. On my both computers I have same users and groups, so this problem is probably not connected with lack of permissions to run my program.
It must be something else something with bad configuration of X.
Ok, It was bug in python3-xlib. See https://github.com/LiuLang/python3-xlib/issues/6 for details.
It definitely has something to do with the permissions.
To get super user permissions, on Linux you can simply type:
$ sudo su
<input your root password>
Now run the python file again
Hope this helped!
this problem is related to x display server connection policies, by default really restrictive
you can solve this issue by allowing access to the user that is going to be executing that code
if you’re the user that is going to execute plover then the code to be pasted in a shell is
xhost +local:$USER
otherwise you can switch out $USER
with the username of the user that’s going to run the code.
a way to make this change permanent is adding that line of code to your login script, id est ~/.profile
for your user, or for any user at file /etc/profile/
in case you want to suppress command output text you can redirect output to /dev/null
, making the whole command:
xhost +local:$USER > /dev/null
had faced this same issue while trying to run plover.
The permanent proper solution is to add the allowed hosts and users to /etc/Xn.hosts
where n stands for the display number (e.g. /etc/X0.hosts
).
The following content will allow all users for localhost (without trailing whitespaces):
local: