[New-bugs-announce] [issue17429] platform.platform() can throw Unicode error

Toshio Kuratomi report at bugs.python.org
Fri Mar 15 16:08:30 CET 2013


New submission from Toshio Kuratomi:

Tested on python-3.2 and python-3.3.  platform.platform() looks for a file in /etc/ that looks like it will contain the name of the Linux distribution that python3 is running on.  Once found, it reads the contents of the file to have a name for the Linux distribution.  Most Linux distributions do create files inside of /etc/ with a single line which is the distribution name so this is a good heuristic.  However, these files are created by the operating system vendor and so they can have a different encoding than the encoding of the locale the user uses.  This means that if there are non-ascii characters inside the file, user code that invokes platform.platform() may throw a traceback.

Test:

$ LC_ALL=en_US.utf8 sudo echo ' Café' >> /etc/fedora-release
$ LC_ALL=C python3
>>> import platform
>>> platform.platform()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.2/platform.py", line 1538, in platform
    distname,distversion,distid = dist('')
  File "/usr/lib64/python3.2/platform.py", line 358, in dist
    full_distribution_name=0)
  File "/usr/lib64/python3.2/platform.py", line 329, in linux_distribution
    firstline = f.readline()
  File "/usr/lib64/python3.2/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 22: ordinal not in range(128)

It seems that the standard method of fixing these that we're promoting in python3 is to use surrogateescape.  I'll provide a patch that does that.

----------
messages: 184234
nosy: a.badger
priority: normal
severity: normal
status: open
title: platform.platform() can throw Unicode error
versions: Python 3.2, Python 3.3

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17429>
_______________________________________


More information about the New-bugs-announce mailing list