Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python connman连接到服务:DBus未知方法_Python_Error Handling_Dbus_Connman - Fatal编程技术网

Python connman连接到服务:DBus未知方法

Python connman连接到服务:DBus未知方法,python,error-handling,dbus,connman,Python,Error Handling,Dbus,Connman,我编写了一个简单的Python脚本来注册代理并连接到connman服务: #!/usr/bin/python import gobject import dbus import dbus.service import dbus.mainloop.glib class Agent(dbus.service.Object): @dbus.service.method("net.connman.Agent", in_signature='oa{sv}', out_signature='a{

我编写了一个简单的Python脚本来注册代理并连接到connman服务:

#!/usr/bin/python

import gobject
import dbus
import dbus.service
import dbus.mainloop.glib

class Agent(dbus.service.Object):
    @dbus.service.method("net.connman.Agent", in_signature='oa{sv}', out_signature='a{sv}')
    def RequestInput(self, path, fields):
        print(path, fields)
        # TODO: fill the requested fields
        response = None
        return response

def Scan(technology):
    path = "/net/connman/technology/" + technology
    technology = dbus.Interface(bus.get_object("net.connman", path), "net.connman.Technology")
    technology.Scan()

def FindService(ssid):
    for path, properties in manager.GetServices():
        name = properties["Name"]
        security = extract_list(properties["Security"])
        if (ssid == name):
            return (path, properties)

    return (None, None)

def Connect(ssid, passphrase):
    Scan("wifi")
    path, properties = FindService(ssid)
    if (path is None):
        print("Service with ssid =", ssid, "not found.")
        return

    print("path:", path)
    service = dbus.Interface(bus.get_object("net.connman", path), "net.connmann.Service")
    print("Connecting...");

    try:
        service.Connect(timeout=10000)
        print("Done!")
    except dbus.DBusException as error:
        print("Failed: ", error._dbus_error_name, error.get_dbus_message())

if __name__ == '__main__':
    dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)

    ssid = "mySSID"
    passphrase = "myPassphrase"

    bus = dbus.SystemBus()
    manager = dbus.Interface(bus.get_object('net.connman', "/"), 'net.connman.Manager')
    path = "/test/agent"
    object = Agent(bus, path)
    object.ssid = ssid

    try:
        manager.RegisterAgent(path)
        print("Agent registered!")

    except:
        print("Cannot register connman agent.")

    Connect(ssid, passphrase)

    mainloop = gobject.MainLoop()
    mainloop.run()
这是输出:

Agent registered!
path: /net/connman/service/wifi_b723ec7500fd_464153545735422d312d43217351_managed_wep
Connecting...
Failed:  org.freedesktop.DBus.Error.UnknownMethod 
Method "Connect" with signature "" on interface "net.connmann.Service" doesn't exist
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
   <interface name="org.freedesktop.DBus.Introspectable">
      <method name="Introspect">
         <arg name="xml" type="s" direction="out" />
      </method>
   </interface>
   <interface name="net.connman.Service">
      <method name="GetProperties">
         <arg name="properties" type="a{sv}" direction="out" />
         <annotation name="org.freedesktop.DBus.Deprecated" value="true" />
      </method>
      <method name="SetProperty">
         <arg name="name" type="s" direction="in" />
         <arg name="value" type="v" direction="in" />
      </method>
      <method name="ClearProperty">
         <arg name="name" type="s" direction="in" />
      </method>
      <method name="Connect" />
      <method name="Disconnect" />
      <method name="Remove" />
      <method name="MoveBefore">
         <arg name="service" type="o" direction="in" />
      </method>
      <method name="MoveAfter">
         <arg name="service" type="o" direction="in" />
      </method>
      <method name="ResetCounters" />
      <signal name="PropertyChanged">
         <arg name="name" type="s" />
         <arg name="value" type="v" />
      </signal>
   </interface>
</node>
代理似乎已注册,但服务接口无法识别“Connect”方法。 根据文件规定,应存在:

test connman脚本也将其称为:

调试此类问题的最佳方法是什么

我还添加了几行来查看该路径上的可用方法:

object = dbus.Interface(service, "org.freedesktop.DBus.Introspectable")
print(object.Introspect())
这是输出:

Agent registered!
path: /net/connman/service/wifi_b723ec7500fd_464153545735422d312d43217351_managed_wep
Connecting...
Failed:  org.freedesktop.DBus.Error.UnknownMethod 
Method "Connect" with signature "" on interface "net.connmann.Service" doesn't exist
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
   <interface name="org.freedesktop.DBus.Introspectable">
      <method name="Introspect">
         <arg name="xml" type="s" direction="out" />
      </method>
   </interface>
   <interface name="net.connman.Service">
      <method name="GetProperties">
         <arg name="properties" type="a{sv}" direction="out" />
         <annotation name="org.freedesktop.DBus.Deprecated" value="true" />
      </method>
      <method name="SetProperty">
         <arg name="name" type="s" direction="in" />
         <arg name="value" type="v" direction="in" />
      </method>
      <method name="ClearProperty">
         <arg name="name" type="s" direction="in" />
      </method>
      <method name="Connect" />
      <method name="Disconnect" />
      <method name="Remove" />
      <method name="MoveBefore">
         <arg name="service" type="o" direction="in" />
      </method>
      <method name="MoveAfter">
         <arg name="service" type="o" direction="in" />
      </method>
      <method name="ResetCounters" />
      <signal name="PropertyChanged">
         <arg name="name" type="s" />
         <arg name="value" type="v" />
      </signal>
   </interface>
</node>

没有签名的连接方法在那里!为什么它说:UnknownMethod?

中有一个双“n” net.connmann.Service

应该是

net.connman.Service