UnicodeDecodeError in Python 3 #84
Comments
|
You need to provide more context, what is the call that triggers this exception? Because using Xlib/protocol/request.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git i/Xlib/protocol/request.py w/Xlib/protocol/request.py
index 578f4a6..7087273 100644
--- i/Xlib/protocol/request.py
+++ w/Xlib/protocol/request.py
@@ -1089,7 +1089,7 @@ class GetImage(rq.ReplyRequest):
rq.ReplyLength(),
rq.Card32('visual'),
rq.Pad(20),
- rq.String8('data'),
+ rq.Binary('data'),
)
class PolyText8(rq.Request): |
|
See #88. |
|
For more context, you may refer to #86 . Since you didn't document class I guess fixing the |
|
I don't see how #86 is related. Historically, When not explicitly specified (see #52 (comment)), X11 text strings should be using the Host Portable Character Encoding (basically ASCII). So I agree that the fact that on Python 3 we end up using UTF-8 is not right, but neither would using Latin-1. Instead I think we should be using ASCII, as in Python 2, so we can detect all invalid use of |
|
Tentative patch: Xlib/protocol/rq.py | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git i/Xlib/protocol/rq.py w/Xlib/protocol/rq.py
index c945c62..f0962e9 100644
--- i/Xlib/protocol/rq.py
+++ w/Xlib/protocol/rq.py
@@ -34,6 +34,10 @@ from .. import X
from ..support import lock
+def decode_string(bs):
+ return bs.decode('ascii')
+
+
class BadDataError(Exception): pass
# These are struct codes, we know their byte sizes
@@ -424,17 +428,14 @@ class String8(ValueField):
def parse_binary_value(self, data, display, length, format):
if length is None:
- return data.decode(), b''
+ return decode_string(data), b''
if self.pad:
slen = length + ((4 - length % 4) % 4)
else:
slen = length
- if sys.version_info < (3, 0):
- data_str = data[:length]
- else:
- data_str = data[:length].decode()
+ data_str = decode_string(data[:length])
return data_str, data[slen:]
@@ -903,7 +904,7 @@ class StrClass(object):
def parse_binary(self, data, display):
slen = byte2int(data) + 1
- return data[1:slen].decode(), data[slen:]
+ return decode_string(data[1:slen]), data[slen:]
Str = StrClass()
|

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

python-xlib/Xlib/protocol/rq.py
Line 427 in 63d5cf1
This line caused a decoding error when run with Python 3.6:
I'm wondering whether
data.decode()will ever work for values in range [128, 256).data.decode('latin1')solves my issue. But I think there may be similar cases in other parts of the project.Pull Request: #85
The default encoding in Python 3 is
utf-8, which doesn't work in this case.asciiwon't work, either.The text was updated successfully, but these errors were encountered: