代码之家  ›  专栏  ›  技术社区  ›  stuudent

python中通过mod_wsgi的Dbus连接

  •  2
  • stuudent  · 技术社区  · 15 年前



    我使用的是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]
    
    1 回复  |  直到 15 年前
        1
  •  0
  •   stuudent    15 年前

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