python中通过mod_wsgi的Dbus连接
python中通过mod_wsgi的Dbus连接,python,apache2,mod-wsgi,Python,Apache2,Mod Wsgi,我正在尝试编写一个小应用程序,它允许通过网页发送dbus命令(到Amarok) 我使用python+mod_wsgi,因为我需要使用与Amarok相同的用户运行脚本。 当我通过普通外壳连接到Amarok时,它可以工作。但是通过脚本连接后,我得到以下错误: DBusException: org.freedesktop.DBus.Error.Spawn.ExecFailed: /usr/bin/dbus-launch terminated abnormally with the following
我正在尝试编写一个小应用程序,它允许通过网页发送dbus命令(到Amarok)
我使用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.
连接到Amarok的代码:
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
config.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):
问题是我没有设置DISPLAY变量,这是连接dbus所必需的。 您可以查看此网页上的小教程:
问题在于我没有设置DISPLAY变量,这是连接dbus所必需的。 您可以查看此网页上的小教程:
没有人?我还没找到答案呢没人?到目前为止我还没有找到答案
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]