gpt4 book ai didi

Python dbus 找不到 org.(gnome|freedesktop).ScreenSaver

转载 作者:太空狗 更新时间:2023-10-30 03:07:30 50 4
gpt4 key购买 nike

我正在尝试让 python 与 dbus 和屏幕保护程序交互,但无论如何它断然拒绝这样做。 Perl 似乎没问题,但我写的是 python,而不是 perl(还)

Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import dbus
>>> bus = dbus.SystemBus()
>>> ofn = 'org.freedesktop.ScreenSaver'
>>> bus.get_object(ofn, "/org/freedesktop/ScreenSaver")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 244, in get_object
follow_name_owner_changes=follow_name_owner_changes)
File "/usr/lib/pymodules/python2.6/dbus/proxies.py", line 241, in __init__
self._named_service = conn.activate_name_owner(bus_name)
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 183, in activate_name_owner
self.start_service_by_name(bus_name)
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 281, in start_service_by_name
'su', (bus_name, flags)))
File "/usr/lib/pymodules/python2.6/dbus/connection.py", line 620, in call_blocking
message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.ScreenSaver was not provided by any .service files
>>>

这是我在 perl 的其他地方看到的:

my $cmd = "dbus-monitor --session \"type='signal',interface='org.gnome.ScreenSaver',member='SessionIdleChanged'\"";

open (IN, "$cmd |");

while (<IN>) {
if (m/^\s+boolean true/) {
#print something
} elsif (m/^\s+boolean false/) {
#print something else
}
}

最佳答案

In [36]: import dbus

In [37]: bus = dbus.SessionBus()

In [38]: bus.get_object('org.gnome.ScreenSaver','/org/gnome/ScreenSaver')
Out[38]: <ProxyObject wrapping <dbus._dbus.SessionBus (session) at 0xa41e38c> :1.24 /org/gnome/ScreenSaver at 0xa4a3b0c>

关于Python dbus 找不到 org.(gnome|freedesktop).ScreenSaver,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4442584/

50 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com