html.decode(encoding) breaks

Issue #295 duplicate
Former user created an issue

/lib/python2.7/site-packages/coverage/", line 255, in html_file html = html.decode(encoding) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 9976: ordinal not in range(128)

Running under py3.3 works fine, with py2.7 it breaks. Seems encoding (ascii) is not correct (source_encoding)

Here is a part of the string:

a[9976-100:9976+100] "30' class='pln'>&nbsp; &nbsp; <span class='com'># negating the effect of persistent connections. Don\xe2\x80\x99t enable them during development.</span><span class='strut'>&nbsp;</span></p>\n<p id='t31' class='"

Comments (2)

  1. Ned Batchelder repo owner

    If your source file has an encoding declaration at the top, the HTML report will work properly. Because the characters are in a comment, Python is probably fine without the declaration, but will need it:

    # -*- coding: utf-8 -*-
  2. Log in to comment