black
black copied to clipboard
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Describe the bug
To Reproduce
Expected behavior
Environment (please complete the following information):
- Version:
- OS and Python version:
Does this bug also happen on main?
Additional context
simply running black run.py
on my file brings up this error
Traceback (most recent call last):
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "D:\resume\quantum-bot\venv\Scripts\black.exe\__main__.py", line 7, in <module>
File "d:\resume\quantum-bot\venv\lib\site-packages\black\__init__.py", line 1283, in patched_main
main()
File "d:\resume\quantum-bot\venv\lib\site-packages\click\core.py", line 1137, in __call__
return self.main(*args, **kwargs)
File "d:\resume\quantum-bot\venv\lib\site-packages\click\core.py", line 1062, in main
rv = self.invoke(ctx)
File "d:\resume\quantum-bot\venv\lib\site-packages\click\core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "d:\resume\quantum-bot\venv\lib\site-packages\click\core.py", line 763, in invoke
return __callback(*args, **kwargs)
File "d:\resume\quantum-bot\venv\lib\site-packages\click\decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
File "d:\resume\quantum-bot\venv\lib\site-packages\black\__init__.py", line 433, in main
sources = get_sources(
File "d:\resume\quantum-bot\venv\lib\site-packages\black\__init__.py", line 501, in get_sources
gitignore = get_gitignore(root)
File "d:\resume\quantum-bot\venv\lib\site-packages\black\files.py", line 125, in get_gitignore
lines = gf.readlines()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.2032.0_x64__qbz5n2kfra8p0\lib\codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
Looks like you have a gitignore file that contains invalid UTF-8.
its just venv
and the error still happens
Anyone got some ideas or should i just close this
run.py
@lukehodges what are the contents of run.py
?
no clue this was from ages ago
@lukehodges I'd say this is worth closing then?
Closing as there's no reproduction steps. If anyone runs into something similar, please open a new issue with full reproduction steps.
@lukehodges
I had the same error with using black on a directory with a .gitignore
file that had */venv/*
removing this resolved the issue.
I had the same issue, my .gitignore file was edited by a windows app and was saved in "UTF-16 LE with BOM", converting it to UTF-8 worked like a charm.
The error is somewhat misleading however, as I (and I suspect most users) would look for the python file we tried to format, not the .gitignore file. Could we catch this error and report that we're trying to parse the .gitgnore file, rather than python source?