[issue13518] configparser

Łukasz Langa report at bugs.python.org
Fri Dec 2 02:04:33 CET 2011


Łukasz Langa <lukasz at langa.pl> added the comment:

Hello, Mickey. By doing open('file', 'rb') you're explicitly stating you want the file to be opened in BINARY mode which means it doesn't return strings but bytes. This is not supported anymore in Python 3. This is clearly documented here: http://docs.python.org/dev/library/configparser.html#configparser.ConfigParser.read_file

Same goes for urllib.request.urlopen, it returns bytes because this is all Python knows at the time of reading the URL. If you happen to know the encoding (for instance by parsing the data or headers) you can do something like this: http://docs.python.org/dev/library/urllib.request.html#examples . Your example would become:

config.read_string(urlopen(path_config).read().decode('utf-8'))

Since this is a reasonable mistake to make, I'm leaving this open to adjust the exception raised if read() yields bytes instead of expected strings.

----------
assignee:  -> lukasz.langa
components: +Library (Lib) -Build
keywords: +easy
priority: normal -> low
versions: +Python 3.3

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


More information about the Python-bugs-list mailing list