I just want to show notification in KDE environment.So i tried pynotifytest.py
from pynotify import *
init("test")
Notification("test", "test").show()
then i run sudo python pynotifytest.py
,the error i got was:
No protocol specified
/usr/lib/python2.7/site-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display warnings.warn(str(e), _gtk.Warning)
----> 3 Notification("test", "test").show()
Error: Command line `dbus-launch --autolaunch=cb94cb23372d0aff09ce7d8a000024b4 --binary-syntax --close-stderr' exited with non-zero exit status 1: No protocol specified\nAutolaunch error: X11 initialization failed.
then i tried to drop privilege pynotifytest.py
import os
os.setuid(1000)
from pynotify import *
init("test")
Notification("test", "test").show()
still i got the same error only in KDE.In gnome-shell and awesome the notification show up as expected.I have a python program must running with root privilege so i can't leave sudo behind. 1000 is my user's uid logging in X.
My linux distribution is Arch. Thanks
To allow sudo to start graphical application in X, you need to add:
Defaults env_keep += "HOME"
to visudo.
"it works for me" -- please give more details of your system. It worked on a fedora 15 with SELinux disabled here. Also note that the problem you are getting is on the GTK+ part - not pynotify per se.
Also - does your user "1000" is the one logged in the graphical environment? Of course this won't work if you are trying to diaplay windows with a user other than the one logged in or root itself.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.