Bug#928655: python3-debian: decode error when using debian_support.PackageFile
Shengjing Zhu
zhsj at debian.org
Wed May 8 12:41:44 BST 2019
Package: python3-debian
Version: 0.1.34
Severity: important
Dear Maintainer,
When using debian_support.PackageFile with python3, it reports:
```
In [1]: from debian import debian_support
In [2]: list(debian_support.PackageFile('/var/lib/apt/lists/mirrors.ustc.edu.cn_debian_dists_buster_main_binary-amd64_Packages'))
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-a7a4671a89a0> in <module>()
----> 1 list(debian_support.PackageFile('/var/lib/apt/lists/mirrors.ustc.edu.cn_debian_dists_buster_main_binary-amd64_Packages'))
/usr/lib/python3/dist-packages/debian/debian_support.py in __iter__(self)
394
395 def __iter__(self):
--> 396 line = self.file.readline().decode()
397 self.lineno += 1
398 pkg = []
AttributeError: 'str' object has no attribute 'decode'
```
The default file is open in text i/o, thus it produces str objects.
If I use it in python2, it reports:
```
>>> from debian import debian_support
>>> list(debian_support.PackageFile('/var/lib/apt/lists/mirrors.ustc.edu.cn_debian_dists_buster_main_binary-amd64_Packages'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/debian/debian_support.py", line 416, in __iter__
line = self.file.readline().decode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 13: ordinal not in range(128)
```
The packages file has utf-8 characters, so you should use
decode('utf-8')...
-- System Information:
Debian Release: buster/sid
APT prefers testing-debug
APT policy: (500, 'testing-debug'), (500, 'testing'), (100, 'unstable'), (1, 'experimental')
Architecture: amd64 (x86_64)
Foreign Architectures: i386
Kernel: Linux 4.19.0-4-amd64 (SMP w/4 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8), LANGUAGE=en_US:en (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: systemd (via /run/systemd/system)
Versions of packages python3-debian depends on:
ii python3 3.7.2-1
ii python3-chardet 3.0.4-3
ii python3-six 1.12.0-1
Versions of packages python3-debian recommends:
ii python3-apt 1.8.4
Versions of packages python3-debian suggests:
ii gpgv 2.2.12-1
-- no debconf information
More information about the pkg-python-debian-maint
mailing list