[Tutor] script guidelines

Steven D'Aprano steve at pearwood.info
Fri Oct 6 06:34:18 EDT 2017

On Fri, Oct 06, 2017 at 03:37:36PM +0530, renukesh nk wrote:
> currently m using pycharm , interpreter = python 3.6
> i am getting th error as below, what might be the reason for this.
> UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 159:
> character maps to <undefined>

When you get an error, Python prints a full traceback showing the full 
chain of function calls. This is useful. Without it, we cannot even 
begin to solve the problem.

All we can say is that, somewhere, somehow, for some reason, you are 
trying to decode some bytes from somewhere (we don't know where) to 
text, and there is an error doing so.

If I look deeply into my magic crystal ball, I *think* the problem is 
that you are trying to read a file (maybe a HTML file downloaded from 
the Internet?) which is encoded differently than you expect. But I can't 
replicate the error you get:

py> b'\x81'.decode('utf-8')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x81 in position 0: 
invalid start byte

If this is a HTML file, have you tried inspecting the HTML to see what 
encoding you should use?


More information about the Tutor mailing list