我使用的是python+mod_wsgi,因为我需要使用与Amarok相同的用户运行脚本。
当我通过普通外壳连接到Amarok时,它就工作了。但通过脚本连接后,我得到以下错误:
DBusException: org.freedesktop.DBus.Error.Spawn.ExecFailed: /usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
import dbus
conn = dbus.SessionBus().get_object('org.kde.amarok','/Player')
你知道我该怎么做才能通过dbus连接到Amarok吗?
更新:
httpd.conf格式:
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /amarok /var/www/amarok-python/config.wsgi
WSGIDaemonProcess l user=wojtas group=wojtas processes=1
WSGIProcessGroup l
配置WSGI:
import sys
path='/var/www/amarok-python'
if path not in sys.path:
sys.path.append(path)
import index
application=index.application
应用程序代码(index.py):
import dbus
from os import getuid
def connect():
conn = dbus.SessionBus().get_object('org.kde.amarok','/Player')
conn.Start()
return conn
def application(environ,start_response):
status= '200 OK'
connection=connect()
output=str(getuid())
response_headers= [('Content-type','text/html'), ('Content-Length', str(len(output)))]
start_response (status,response_headers)
return [output]