-
-
Notifications
You must be signed in to change notification settings - Fork 439
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 #303
Comments
Original comment by douglasbsf (Bitbucket: douglasbsf, GitHub: douglasbsf) Solution: html = html.decode(encoding,'ignore') on /coverage/html.py line 253 |
Can you please provide more detail? In particular, a reproducible test case would be appreciated. My guess is that you have a non-ASCII character in a comment in your source file, and that if you add a coding comment to the top, coverage will work fine:
|
Original comment by douglasbsf (Bitbucket: douglasbsf, GitHub: douglasbsf) I tried this solution, but here it's didn't work. So I tried the proposed solution. |
Original comment by douglasbsf (Bitbucket: douglasbsf, GitHub: douglasbsf) Another detail: I'm using django unit test like this: coverage run --source='.' manage.py test client.tests . |
Is there any chance you could supply a reproducible test case? |
Original comment by douglasbsf (Bitbucket: douglasbsf, GitHub: douglasbsf) It's a piece of a IPTV project (Private) and It's only work complete. I would like but I can't. |
Issue #295 was marked as a duplicate of this issue. |
Original comment by Robert Sussland (Bitbucket: rsussland, GitHub: rsussland) I am having the same issue. There are no non-unicode characters in any of the python source files, however the test suite I am running coverage on downloads files with unicode file names and processes file with unicode characters. I cannot send you my code as it is pulling data from an on-site database. The stack trace doesn't show which file triggered the error:
|
Original comment by Ian Cordasco (Bitbucket: icordasc, GitHub: Unknown) The problem is that ignoring errors when encoding unicode in ascii is that you're going to lose data. What data is trying to be used, I'm not certain, but @rsussland could you please put your traceback in a fenced code block, i.e., precede it with three backticks and a newline, and follow it by a newline and three backticks. That will make it much easier to read. |
Original comment by Ian Cordasco (Bitbucket: icordasc, GitHub: Unknown) So I'm looking at this code, and I'm wondering why |
Original comment by Robert Sussland (Bitbucket: rsussland, GitHub: rsussland) I'm not familiar enough with this code to determine whether the policy is to work with code points or bytestrings, but unless you import unicode_literals, 'foo bar bogus' is already an ascii encoded byte string, so calling encode on it will decode with the ascii codec and re-encode it with the same codec. If you are intending to work with code points then you do need to decode, but I don't see any of the standard patterns for doing that in the html.py file -- for example, you are calling with open instead of with codecs.open, so your other strings are already encoded as bytestrings and not code points, in which case no need to decode at all, but care must be taken when combining bytestrings of different encodings (they are all ascii byte strings). |
@rsussland The line of code in question is dealing with the HTML version of your source files. I find it very hard to believe that you have no non-ascii characters in your source file. Perhaps in a comment? A curly apostrophe? The data you download for your tests doesn't matter, that isn't part of the HTML report. In Python 2.7, do this:
Does it succeed, or raise an exception? Also, it looks like your file is really large? Can you share any of the code with me? |
Sorry, I see that you say the file isn't in the error message. At the very least, I can add some information there so these problems are easier to diagnose while we decide on an approach. |
OK, I added better error reporting in e5c3104996da (bb) . Can you use it to provide some more information about your failure? |
I've fixed this in 529fef3d32ab (bb) Regardless of how a Python file has undecodable characters in it, we should prevent errors from stopping the HTML report. |
Originally reported by douglasbsf (Bitbucket: douglasbsf, GitHub: douglasbsf)
The text was updated successfully, but these errors were encountered: