简体   繁体   English

在KDE中使用sudo运行时,python脚本中的pynotify出错

[英]pynotify in python script go wrong when running with sudo in KDE

I just want to show notification in KDE environment.So i tried pynotifytest.py 我只想在KDE环境中显示通知。所以我尝试了pynotifytest.py

from pynotify import *
init("test")
Notification("test", "test").show()

then i run sudo python pynotifytest.py ,the error i got was: 然后我运行sudo python pynotifytest.py ,我得到的错误是:

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 然后我试图放弃特权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. 我仍然只在KDE中遇到相同的错误。在gnome-shell中,通知显示如预期的那样好。我有一个python程序必须以root特权运行,所以我不能将sudo抛在后面。 1000 is my user's uid logging in X. 1000是我的用户在X中登录的uid。

My linux distribution is Arch. 我的Linux发行版是Arch。 Thanks 谢谢

To allow sudo to start graphical application in X, you need to add: 要允许sudo在X中启动图形应用程序,您需要添加:

Defaults env_keep += "HOME"

to visudo. visudo。

"it works for me" -- please give more details of your system. “对我有用”-请提供系统的更多详细信息。 It worked on a fedora 15 with SELinux disabled here. 它适用于在此处禁用SELinux的fedora 15。 Also note that the problem you are getting is on the GTK+ part - not pynotify per se. 另请注意,您遇到的问题是GTK +部分-本身不是pynotify。

Also - does your user "1000" is the one logged in the graphical environment? 另外-您的用户“ 1000”是登录图形环境的用户吗? 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. 当然,如果您尝试与非登录用户或root用户本身一起播放Windows,这将无法正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM