Я следую учебному руководству по разработке Bluetooth для Linux, которое можно найти здесь, и я новичок в программировании DBus.
В руководстве используется Python для взаимодействия с системной DBus следующим образом.< /p>
Код: Выделить всё
#!/usr/bin/python3
import dbus
bus = dbus.SystemBus()
proxy = bus.get_object('org.freedesktop.hostname1','/org/freedesktop/hostname1')
interface = dbus.Interface(proxy, 'org.freedesktop.Dbus.Properties')
print("----------------")
hostname = interface.Get('org.freedesktop.hostname1','Hostname')
print("The host name is ",hostname)
Код: Выделить всё
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.UnknownMethod: Unknown method Get or interface org.freedesktop.Dbus.Properties.
Я сделал захват pcap для Wireshark с помощью dbus-monitor и сравнил запрос d-feet с dbus Python запрос, и я не могу понять, в чем проблема. Оба запроса отправляются в один и тот же пункт назначения и имеют одинаковую структуру с одинаковыми деталями, за исключением того, что массив элементов словаря находится в другом порядке (не уверен, имеет ли это значение).
< p>Запрос на d-футы:
Код: Выделить всё
Frame 17: 197 bytes on wire (1576 bits), 197 bytes captured (1576 bits)
Encapsulation type: D-Bus (146)
Arrival Time: Mar 13, 2024 07:21:04.048618000 AEDT
[Time shift for this packet: 0.000000000 seconds]
Epoch Time: 1710274864.048618000 seconds
[Time delta from previous captured frame: 0.001328000 seconds]
[Time delta from previous displayed frame: 0.001328000 seconds]
[Time since reference or first frame: 2.546796000 seconds]
Frame Number: 17
Frame Length: 197 bytes (1576 bits)
Capture Length: 197 bytes (1576 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: dbus]
D-Bus
Endianness: little-endian
Message Type: Method call
Message Flags: 0x00
.... ...0 = No Reply Expected: Expected
.... ..0. = No Auto Start: Start
.... .0.. = Allow Interactive Authorization: Don't allow
Protocol Version: 1
Message Body Length: 45
Message Serial: 623
Header Field Array
Array Length: 134
Dict Entry, 1, Path: /org/freedesktop/hostname1
Field Code: Path (1)
Variant: /org/freedesktop/hostname1
Variant Signature: o
Path: /org/freedesktop/hostname1
Dict Entry, 2, Interface: org.freedesktop.DBus.Properties
Field Code: Interface (2)
Variant: org.freedesktop.DBus.Properties
Variant Signature: s
Interface: org.freedesktop.DBus.Properties
Dict Entry, 6, Destination: :1.171
Field Code: Destination (6)
Variant: :1.171
Variant Signature: s
Destination: :1.171
Dict Entry, 8, Signature: ss
Field Code: Signature (8)
Variant: ss
Variant Signature: g
Signature: ss
Dict Entry, 3, Member: Get
Field Code: Member (3)
Variant: Get
Variant Signature: s
Member: Get
Dict Entry, 7, Sender: :1.83
Field Code: Sender (7)
Variant: :1.83
Variant Signature: s
Sender: :1.83
Body
String: org.freedesktop.hostname1
String: Hostname
Код: Выделить всё
Frame 18: 86 bytes on wire (688 bits), 86 bytes captured (688 bits)
Encapsulation type: D-Bus (146)
Arrival Time: Mar 13, 2024 07:21:04.048994000 AEDT
[Time shift for this packet: 0.000000000 seconds]
Epoch Time: 1710274864.048994000 seconds
[Time delta from previous captured frame: 0.000376000 seconds]
[Time delta from previous displayed frame: 0.000376000 seconds]
[Time since reference or first frame: 2.547172000 seconds]
Frame Number: 18
Frame Length: 86 bytes (688 bits)
Capture Length: 86 bytes (688 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: dbus]
D-Bus
Endianness: little-endian
Message Type: Method reply
Message Flags: 0x01
.... ...1 = No Reply Expected: Not expected
.... ..0. = No Auto Start: Start
.... .0.. = Allow Interactive Authorization: Don't allow
Protocol Version: 1
Message Body Length: 22
Message Serial: 10
Header Field Array
Array Length: 47
Dict Entry, 5, Reply serial: 623
Field Code: Reply serial (5)
Variant: 623
Variant Signature: u
Reply serial: 623
Dict Entry, 6, Destination: :1.83
Field Code: Destination (6)
Variant: :1.83
Variant Signature: s
Destination: :1.83
Dict Entry, 8, Signature: v
Field Code: Signature (8)
Variant: v
Variant Signature: g
Signature: v
Dict Entry, 7, Sender: :1.171
Field Code: Sender (7)
Variant: :1.171
Variant Signature: s
Sender: :1.171
Body
Variant: Lenny-Leonard
Variant Signature: s
String: Lenny-Leonard
Код: Выделить всё
Frame 34: 197 bytes on wire (1576 bits), 197 bytes captured (1576 bits)
Encapsulation type: D-Bus (146)
Arrival Time: Mar 13, 2024 07:21:06.564106000 AEDT
[Time shift for this packet: 0.000000000 seconds]
Epoch Time: 1710274866.564106000 seconds
[Time delta from previous captured frame: 0.000312000 seconds]
[Time delta from previous displayed frame: 0.000312000 seconds]
[Time since reference or first frame: 5.062284000 seconds]
Frame Number: 34
Frame Length: 197 bytes (1576 bits)
Capture Length: 197 bytes (1576 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: dbus]
D-Bus
Endianness: little-endian
Message Type: Method call
Message Flags: 0x00
.... ...0 = No Reply Expected: Expected
.... ..0. = No Auto Start: Start
.... .0.. = Allow Interactive Authorization: Don't allow
Protocol Version: 1
Message Body Length: 45
Message Serial: 4
Header Field Array
Array Length: 135
Dict Entry, 1, Path: /org/freedesktop/hostname1
Field Code: Path (1)
Variant: /org/freedesktop/hostname1
Variant Signature: o
Path: /org/freedesktop/hostname1
Dict Entry, 6, Destination: :1.171
Field Code: Destination (6)
Variant: :1.171
Variant Signature: s
Destination: :1.171
Dict Entry, 2, Interface: org.freedesktop.Dbus.Properties
Field Code: Interface (2)
Variant: org.freedesktop.Dbus.Properties
Variant Signature: s
Interface: org.freedesktop.Dbus.Properties
Dict Entry, 3, Member: Get
Field Code: Member (3)
Variant: Get
Variant Signature: s
Member: Get
Dict Entry, 8, Signature: ss
Field Code: Signature (8)
Variant: ss
Variant Signature: g
Signature: ss
Dict Entry, 7, Sender: :1.173
Field Code: Sender (7)
Variant: :1.173
Variant Signature: s
Sender: :1.173
Body
String: org.freedesktop.hostname1
String: Hostname
Код: Выделить всё
Frame 35: 189 bytes on wire (1512 bits), 189 bytes captured (1512 bits)
Encapsulation type: D-Bus (146)
Arrival Time: Mar 13, 2024 07:21:06.564291000 AEDT
[Time shift for this packet: 0.000000000 seconds]
Epoch Time: 1710274866.564291000 seconds
[Time delta from previous captured frame: 0.000185000 seconds]
[Time delta from previous displayed frame: 0.000185000 seconds]
[Time since reference or first frame: 5.062469000 seconds]
Frame Number: 35
Frame Length: 189 bytes (1512 bits)
Capture Length: 189 bytes (1512 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: dbus]
D-Bus
Endianness: little-endian
Message Type: Error reply
Message Flags: 0x01
.... ...1 = No Reply Expected: Not expected
.... ..0. = No Auto Start: Start
.... .0.. = Allow Interactive Authorization: Don't allow
Protocol Version: 1
Message Body Length: 69
Message Serial: 12
Header Field Array
Array Length: 103
Dict Entry, 5, Reply serial: 4
Field Code: Reply serial (5)
Variant: 4
Variant Signature: u
Reply serial: 4
Dict Entry, 6, Destination: :1.173
Field Code: Destination (6)
Variant: :1.173
Variant Signature: s
Destination: :1.173
Dict Entry, 4, Error name: org.freedesktop.DBus.Error.UnknownMethod
Field Code: Error name (4)
Variant: org.freedesktop.DBus.Error.UnknownMethod
Variant Signature: s
Error name: org.freedesktop.DBus.Error.UnknownMethod
Dict Entry, 8, Signature: s
Field Code: Signature (8)
Variant: s
Variant Signature: g
Signature: s
Dict Entry, 7, Sender: :1.171
Field Code: Sender (7)
Variant: :1.171
Variant Signature: s
Sender: :1.171
Body
String: Unknown method Get or interface org.freedesktop.Dbus.Properties.
Is it possible to send some other requests to discover what methods are available for the selected interface and/or to verify it's the correct interface?
Thanks.
Источник: https://stackoverflow.com/questions/781 ... -interface