gpt4 book ai didi

python - 在 python 中通过 mod_wsgi 连接 Dbus

转载 作者:太空宇宙 更新时间:2023-11-04 06:39:00 24 4
gpt4 key购买 nike


我正在尝试编写允许通过网页发送 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.

连接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


配置.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]

最佳答案

问题是我没有设置连接 dbus 所需的 DISPLAY 变量。您可以查看此网页上的小教程: http://blog.wojtass.pl/tutorial-control-amarok-remotely-through-web-browser/

关于python - 在 python 中通过 mod_wsgi 连接 Dbus,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4059058/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com