nedbat / coveragepy

The code coverage tool for Python
https://coverage.readthedocs.io
Apache License 2.0
2.98k stars 429 forks source link

UnicodeDecodeError: 'utf8' codec can't decode byte 0xef in position 20894: invalid continuation byte #159

Closed nedbat closed 12 years ago

nedbat commented 12 years ago

Originally reported by Zooko O'Whielacronx (Bitbucket: zooko, GitHub: zooko)


PASSED (successes=188)
HACK zompu:~/playground/tahoe-lafs/trunk$ coverage html
Traceback (most recent call last):
  File "/usr/local/bin/coverage", line 9, in <module>
    load_entry_point('coverage==3.5.1', 'console_scripts', 'coverage')()
  File "/usr/local/lib/python2.7/dist-packages/coverage-3.5.1-py2.7-linux-x86_64.egg/coverage/cmdline.py", line 657, in main
    status = CoverageScript().command_line(argv)
  File "/usr/local/lib/python2.7/dist-packages/coverage-3.5.1-py2.7-linux-x86_64.egg/coverage/cmdline.py", line 549, in command_line
    directory=options.directory, **report_args)
  File "/usr/local/lib/python2.7/dist-packages/coverage-3.5.1-py2.7-linux-x86_64.egg/coverage/control.py", line 599, in html_report
    reporter.report(morfs, config=self.config)
  File "/usr/local/lib/python2.7/dist-packages/coverage-3.5.1-py2.7-linux-x86_64.egg/coverage/html.py", line 83, in report
    self.report_files(self.html_file, morfs, config, config.html_dir)
  File "/usr/local/lib/python2.7/dist-packages/coverage-3.5.1-py2.7-linux-x86_64.egg/coverage/report.py", line 86, in report_files
    report_fn(cu, self.coverage._analyze(cu))
  File "/usr/local/lib/python2.7/dist-packages/coverage-3.5.1-py2.7-linux-x86_64.egg/coverage/html.py", line 198, in html_file
    self.write_html(html_path, html)
  File "/usr/local/lib/python2.7/dist-packages/coverage-3.5.1-py2.7-linux-x86_64.egg/coverage/html.py", line 103, in write_html
    write_encoded(fname, html, 'ascii', 'xmlcharrefreplace')
  File "/usr/local/lib/python2.7/dist-packages/coverage-3.5.1-py2.7-linux-x86_64.egg/coverage/backward.py", line 137, in write_encoded
    f.write(text.decode('utf8'))
  File "/usr/lib/python2.7/encodings/utf_8.py", line 16, in decode
    return codecs.utf_8_decode(input, errors, True)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xef in position 20894: invalid continuation byte

nedbat commented 12 years ago

Duplicate of #157.

nedbat commented 12 years ago

Original comment by Anonymous


I get this same error, and yes, I have a couple of tests dealing with latin-1 characters in them. Is a fix for this planned? It's currently blocking our use of html reports with coverage.

nedbat commented 12 years ago

Do you know what file produced the error? Do you have isolatin-1 encoded source files?