Re: Subclass Gio.DBusProxy and UnicodeDecodeError under python 3
- From: infirit <infirit gmail com>
- To: Christoph Reiter <reiter christoph gmail com>, python-hackers-list gnome org
- Subject: Re: Subclass Gio.DBusProxy and UnicodeDecodeError under python 3
- Date: Tue, 27 Dec 2016 17:32:53 +0100
Op 12/13/2016 om 04:31 PM schreef infirit:
Op 12/12/2016 om 11:49 PM schreef Christoph Reiter:
On Sun, Dec 11, 2016 at 6:12 PM, infirit <infirit gmail com> wrote:
Hi all,
I subclassed Gio.DBusProxy and overridden the do_g_properties_changed
virtual function. In there I emit my own signal that consumers of the
proxy can connect to. I have created a minimal example of what I am
doing which you can find on [1].
The code from [1] runs perfectly fine under python2.7 with no
UnicodeDecodeError at any point, the situation under Python 3.4 however
is different. See below an example error. I narrowed it down to
overriding do_g_properties_changed, without that the error goes away.
*connected function* /org/bluez/hci0/dev_7C_2F_80_3B_AF_AB RSSI -64
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb8 in position
0: invalid start byte
The strange thing is that it does not generate a traceback so I am not
entirely sure how to proceed with this. It also does not seem to result
in issues however my gut tells me not to ignore it. Anyone know what is
going on with this?
Under Python 2 text gets passed to Python as is (utf-8 encoded) while
under Python 3 things get decoded to unicode code points. I suspect
there is some invalid utf-8 involved which you should see in data
getting passed to do_g_properties_changed under py2.
I've tested your code (with adjusting the device path) and it seems to
work fine under py3 here.
The problem is printing both properties changed and invalidated
properties is identical between the two python versions. The only
difference is with Python3 at the end I see the error. I monitored the
object from the command line (below) and I see all events back in my
proxy output. However there is something strange with the invalidated
properties, more on that down below.
#gdbus -y -d "org.bluez" -o "/org/bluez/hci0/dev_7C_2F_80_3B_AF_AB"
/org/bluez/hci0/dev_7C_2F_80_3B_AF_AB:
org.freedesktop.DBus.Properties.PropertiesChanged ('org.bluez.Device1',
{'RSSI': <int16 -61>}, @as [])
/org/bluez/hci0/dev_7C_2F_80_3B_AF_AB:
org.freedesktop.DBus.Properties.PropertiesChanged ('org.bluez.Device1',
@a{sv} {}, ['RSSI'])
Corresponding output from my code under python3
*<class '__main__.MyProxy'> : changed*
/org/bluez/hci0/dev_7C_2F_80_3B_AF_AB RSSI -61
*connected function* /org/bluez/hci0/dev_7C_2F_80_3B_AF_AB RSSI -61
*invalidated* <class 'str'> ''
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x90 in position 2:
invalid start byte
and python2
("*<class '__main__.MyProxy'> : changed*",
'/org/bluez/hci0/dev_7C_2F_80_3B_AF_AB', 'RSSI', -61)
('*connected function*', '/org/bluez/hci0/dev_7C_2F_80_3B_AF_AB',
'RSSI', -61)
('*invalidated*', <type 'str'>, "''", '')
Now on the invalidated properties. I personally have need for them but I
did notice the virtual do_g_properties_changed is not handling them
properly. Take the second line from gdbus, it has no changed properties
and one invalidated property. Looking at what I get in
do_g_properties_changed I noticed I always get an empty *string*
(instead of a list). This looks like a bug as it is definitely on the
bus but never shows up in do_g_properties_changed. When I connect
directly (without using the virtual function) to g_properties_changed I
do see the invalidated properties correctly as a *list* of strings.
My guess is that the two are related but I am not sure where to go from
here.
Should I open a bug report?
~infirit
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]