Kod: Zaznacz cały
#!/usr/bin/python
"""
Returns a list of services available as json string
"""
import json, gwibber.lib
gw = gwibber.lib.GwibberPublic()
accounts = json.loads(gw.GetAccounts())
print accounts
Kod: Zaznacz cały
$ ./get_accounts.py
Traceback (most recent call last):
File "./get_accounts.py", line 7, in <module>
gw = gwibber.lib.GwibberPublic()
File "/usr/lib/python2.6/gwibber/lib/__init__.py", line 12, in __init__
self.accounts = self.getbus("Accounts")
File "/usr/lib/python2.6/gwibber/lib/__init__.py", line 20, in getbus
follow_name_owner_changes=True)
File "/usr/lib/pymodules/python2.6/dbus/bus.py", line 226, in get_object
self._require_main_loop() # we don't get the signals otherwise
RuntimeError: To make asynchronous calls, receive signals or export objects, D-Bus connections must be attached to a main loop by passing mainloop=... to the constructor or calling dbus.set_default_main_loop(...)
EDIT:
Ok, poradziłem sobie z pomocą blackfire:
Kod: Zaznacz cały
#!/usr/bin/python
"""
Returns a list of services available as json string
"""
from dbus.mainloop.glib import DBusGMainLoop
import gobject
import json, gwibber.lib
DBusGMainLoop(set_as_default=True)
loop = gobject.MainLoop()
gw = gwibber.lib.GwibberPublic()
accounts = json.loads(gw.GetAccounts())
print accounts
loop.run()