Hot to deal with this UTF-8 Error ?

416 views
Skip to first unread message

Walter Traunmueller

unread,
Dec 20, 2020, 6:18:56 AM12/20/20
to thonny

Traceback (most recent call last):
  File "C:\Users\Administrator\AppData\Local\Programs\Thonny\lib\site-packages\thonny\workbench.py", line 1706, in event_generate
    handler(event)
  File "C:\Users\Administrator\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\debugger.py", line 1212, in _handle_debugger_progress
    _current_debugger.handle_debugger_progress(msg)
  File "C:\Users\Administrator\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\debugger.py", line 181, in handle_debugger_progress
    self.bring_out_frame(self._last_progress_message.stack[-1].id, force=True)
  File "C:\Users\Administrator\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\debugger.py", line 219, in bring_out_frame
    self._last_frame_visualizer._update_this_frame(self._last_progress_message, frame_info)
  File "C:\Users\Administrator\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\debugger.py", line 590, in _update_this_frame
    FrameVisualizer._update_this_frame(self, msg, frame_info)
  File "C:\Users\Administrator\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\debugger.py", line 466, in _update_this_frame
    self._expression_box.update_expression(msg, frame_info)
  File "C:\Users\Administrator\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\debugger.py", line 660, in update_expression
    whole_source, frame_info.filename, frame_info.current_root_expression
  File "C:\Users\Administrator\AppData\Local\Programs\Thonny\lib\site-packages\thonny\plugins\debugger.py", line 733, in _load_expression
    root = ast_utils.parse_source(whole_source, filename)
  File "C:\Users\Administrator\AppData\Local\Programs\Thonny\lib\site-packages\thonny\ast_utils.py", line 38, in parse_source
    mark_text_ranges(root, source, fallback_to_one_char)
  File "C:\Users\Administrator\AppData\Local\Programs\Thonny\lib\site-packages\thonny\ast_utils.py", line 181, in mark_text_ranges
    source = source.decode("utf8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 2103: invalid start byte

...................................................
Comes within debugging. When I debug this script within PyCharm, no error occurs.

What can I do to fix this error in Thonny?

Aivar Annamaa

unread,
Dec 20, 2020, 9:24:47 AM12/20/20
to thonny
Can you post your script as attachment? Which encoding are you using?

Best regards,
Aivar

Walter Traunmueller

unread,
Dec 21, 2020, 6:28:49 AM12/21/20
to thonny
here is my script (please respect my rights, it is a production script). You will need something on COM3 (RS485) to get this work

Dont know which encoding, I thought, Python 3.7 is using UTF-8. Within the whole script I do never use chars outside  UTF-8 and no german Ä Ö Ü

greetings from austria

..: I would like to work with Thonny rather than with PyCharm..
solaredge.py

Aivar Annamaa

unread,
Dec 21, 2020, 7:56:08 AM12/21/20
to thonny
Thank you for the script!

It looks like it has been created in iso-8859-1 (as indicated by the second line of the script), but even with this encoding some of the characters in comments don't look right. Nevertheless, Thonny is also guilty here, because it shouldn't treat the code as UTF-8 in this case. I added this to my TODO list: https://github.com/thonny/thonny/issues/1493

Still, I don't understand why you got this error, because the script as you sent it is decodable with utf-8. I assume you had re-saved it somewhere between getting this error and posting it here.

Do you still get the same error when you debug this script? Right after starting the debugger or after some stepping?

Best regards,
Aivar



--
You received this message because you are subscribed to the Google Groups "thonny" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thonny+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/thonny/9d2d61e9-68fb-467a-a44c-c8ac5467ba27n%40googlegroups.com.

Walter Traunmueller

unread,
Dec 21, 2020, 8:47:53 AM12/21/20
to thonny
Hi there,

I didnt know that chars in comments are the reason, because comments are not executable. I removed all the ü replacing them to ue and now I can debug the script.

The occurance of the error was after stepping till start() with F6 and step into the start()-function with F7.

When working on scripts I switch between PyCharm, Thonny and Notepad++, always doing something which the tool can do the best for me.

What should I write instead of my second line? Something or nothing or what else?  Thank you

Aivar Annamaa

unread,
Dec 21, 2020, 9:16:59 AM12/21/20
to thonny
> What should I write instead of my second line? Something or nothing or what else?

I recommend just deleting the second line, because UTF-8 is the default encoding for Python 3 source files.

Best regards,
Aivar
Reply all
Reply to author
Forward
0 new messages