Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeDecodeError when reading pyproject.toml. #250

Closed
domdfcoding opened this issue Mar 3, 2021 · 0 comments · Fixed by #251
Closed

UnicodeDecodeError when reading pyproject.toml. #250

domdfcoding opened this issue Mar 3, 2021 · 0 comments · Fixed by #251

Comments

@domdfcoding
Copy link
Contributor

build omits the "encoding" parameter when reading pyproject.toml, resulting in a UnicodeDecodeError when the file contains unicode characters unsupported by the system encoding.

The problem code is at:

build/src/build/__init__.py

Lines 143 to 144 in ca34512

with open(spec_file) as f:
spec = toml.load(f)

The traceback is:

Traceback (most recent call last):
  File "C:\hostedtoolcache\windows\Python\3.6.8\x64\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\hostedtoolcache\windows\Python\3.6.8\x64\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "D:\a\domdf_python_tools\domdf_python_tools\.tox\build\lib\site-packages\build\__main__.py", line 214, in <module>
    main(sys.argv[1:], 'python -m build')
  File "D:\a\domdf_python_tools\domdf_python_tools\.tox\build\lib\site-packages\build\__main__.py", line 206, in main
    build_package(args.srcdir, outdir, distributions, config_settings, not args.no_isolation, args.skip_dependencies)
  File "D:\a\domdf_python_tools\domdf_python_tools\.tox\build\lib\site-packages\build\__main__.py", line 92, in build_package
    builder = ProjectBuilder(srcdir)
  File "D:\a\domdf_python_tools\domdf_python_tools\.tox\build\lib\site-packages\build\__init__.py", line 144, in __init__
    spec = toml.load(f)
  File "D:\a\domdf_python_tools\domdf_python_tools\.tox\build\lib\site-packages\toml\decoder.py", line 156, in load
    return loads(f.read(), _dict, decoder)
  File "C:\hostedtoolcache\windows\Python\3.6.8\x64\lib\encodings\cp1252.py", line 23, in decode
    return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 223: character maps to <undefined>

The TOML specification requires files to be encoded in UTF-8, and therefore the fix is as simple as:

with open(spec_file, encoding="UTF-8") as f:
    spec = toml.load(f)

See tox-dev/tox#1908 for the same issue in tox

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant