python中通过mod_wsgi连接Dbus
我正在尝试编写一个小型应用程序,它允许通过网页发送 dbus 命令(到 Amarok)。
我使用 python + mod_wsgi,因为我需要使用与 Amarok 相同的用户运行脚本。
当我通过普通 shell 连接到 Amarok 时,它可以工作。但通过脚本连接后,出现以下错误:
DBusException: org.freedesktop.DBus.Error.Spawn.ExecFailed: /usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
The code which isconnecting to the Amarok:
import dbus
conn = dbus.SessionBus().get_object('org.kde.amarok','/Player')
Do you Know how should I do to connect through dbus to 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):
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]
I'm trying to write small application which allows to send dbus commands (to Amarok) through web page.
I'm using python + mod_wsgi, because I need to run the script with the same user as Amarok.
When I connect to the Amarok through normal shell, it works. But after connecting through the script, I get the following error:
DBusException: org.freedesktop.DBus.Error.Spawn.ExecFailed: /usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
The code which is connecting to the Amarok:
import dbus
conn = dbus.SessionBus().get_object('org.kde.amarok','/Player')
Do you know what should I do to connect through dbus to Amarok?
Thanks a lot for help!
Update:
I'll give you some additional information about configuration:
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
Code of the 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]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是我没有设置连接 dbus 所需的 DISPLAY 变量。
您可以查看此网页上的小教程:
http://blog.wojtass.pl/tutorial-control- amarok-remotely-through-web-browser/
The problem was that I didn't set the DISPLAY variable, which is required for connecting with dbus.
You can check the small tutorial on this webpage:
http://blog.wojtass.pl/tutorial-control-amarok-remotely-through-web-browser/