2

I want to do some Python scripting on my server where I can communicate with finch (A console interface of pidgin, with the interface looking like links2) through the DBus Python library to send messages or check for buddy online status.

This works if you do it in X. Run finch in an X terminal and run the Python script in another terminal with no errors/exceptions.

But if you do it without X, you have to run finch in TTY1 (ctrl+alt+f1) and the python script in TTY2 (ctrl+alt+f2) but the python script will fail.

The following is the first few lines of the script:

import dbus
bus = dbus.SessionBus() # gives EXCEPTION error
obj = bus.get_object("im.pidgin.purple.PurpleService", "/im/pidgin/purple/PurpleObject")
...

The EXCEPTION error is:

dbus.exceptions.DBusException: org.freedesktop.DBus.Error.Spawn.ExecFailed: dbus-launch failed to autolaunch D-Bus session: Autolaunch error: X11 initialization failed.`

I read somewhere that maybe you need to run finch and the script both in the same TTY. However I am unable to test that properly because it is not like running cd on one line and ls on the next line. You type finch , it runs, and you can't type any other commands anymore, like links2. I tried running finch & instead but that seems to pause finch, and running the script also gives the same error.

Solution? Thanks.

Robin
  • 81
  • 1
  • 6
  • I basically want to run a script which messages someone or check someone's status without requiring X. Just something I can ssh into and run the script. Maybe you can give me an alternative solution which doesn't necessarily have to involve finch or dbus. – Robin Apr 04 '11 at 11:19
  • Thanks for asking the question and answering it. – ShreevatsaR Aug 17 '11 at 10:10

2 Answers2

6

Install screen

  1. dbus-launch screen
  2. finch
  3. ctrl+a c
  4. python myscript
Robin
  • 81
  • 1
  • 6
  • So that's the solution, can't mark it as my answer at the moment, gotta do it tomorrow. – Robin Apr 04 '11 at 12:37
  • 1
    Thank you! I have been searching for days regarding why I can't use gvfs on a headless system. Launching dbus this way did the trick! – dotnix Mar 17 '12 at 21:44
  • Thanks for this -- your pointing me to dbus-launch led me to notice that subsequent unrelated terminals can connect to dbus by setting the DBUS_SESSION_BUS_ADDRESS environment variable, which presumably does the job when $DISPLAY is unavailable. – gra Sep 13 '20 at 23:14
0

I think finch needs some display. To launch it on the server try to use xvfb-run: http://en.wikipedia.org/wiki/Xvfb

Alexander
  • 315
  • 2
  • 10