[New-bugs-announce] [issue14311] ConfigParser does not parse utf-8 files with BOM bytes

Sean Wang report at bugs.python.org
Thu Mar 15 03:24:52 CET 2012


New submission from Sean Wang <wangxiao8611 at gmail.com>:

ConfigParser failed to parse a utf-8 file with BOM bytes('\xef\xbb\xbf'),
it would raise ConfigParser.MissingSectionHeaderError.

I think that other files with BOM would have the same problem; because the argument "SECTCRE" does not consider the BOM conditions.

Now the workaround is like below:

cp=ConfigParser.ConfigParser()
cfgfile=os.path.join(curpath,'config.cfg')
cp.readfp(codecs.open(cfgfile, 'r','utf-8-sig'))

----------
components: Library (Lib)
messages: 155843
nosy: Sean.Wang
priority: normal
severity: normal
status: open
title: ConfigParser does not parse utf-8 files with BOM bytes
type: behavior
versions: Python 2.7

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


More information about the New-bugs-announce mailing list