Skip to content

Commit

Permalink
setup: open README.md with a specific encoding
Browse files Browse the repository at this point in the history
With python3, the built-in open() function opens files in "text" mode by
default (i.e. the f.read() method reads bytes and tries to decode them
to unicode using the interpreter default encoding). Depending on the
system locale, this default encoding may be 'ascii'. Which leads to the
following error:

 ~$ python3 setup.py egg_info
 Traceback (most recent call last):
   File "setup.py", line 12, in <module>
     long_description = f.read()
   File "/usr/lib/python3.6/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
 2587: ordinal not in range(128)

The character at position 2587 is 'ô' (from Fantômas) and is utf-8
encoded.

Force to open the file in "binary" mode (which is the only mode on
python2) and explicitly decode the read bytes to unicode using the
'utf-8' codec.

Fixes: 8374e7d ("Use Markdown long_description on PyPI (#190)")
Signed-off-by: Robin Jarry <robin.jarry@6wind.com>
  • Loading branch information
rjarry authored and martinblech committed May 8, 2022
1 parent 072b119 commit 20bc78c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

import xmltodict

with open('README.md') as f:
long_description = f.read()
with open('README.md', 'rb') as f:
long_description = f.read().decode('utf-8')


setup(name='xmltodict',
Expand Down

0 comments on commit 20bc78c

Please sign in to comment.