This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: IDLE should catch user config file UnicodeDecodeError
Type: behavior Stage: test needed
Components: IDLE Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: terry.reedy Nosy List: terry.reedy, 左迟
Priority: normal Keywords:

Created on 2020-04-29 10:05 by 左迟, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
pic04-29-18-05-10.png 左迟, 2020-04-29 10:05 error message
config-main.cfg 左迟, 2020-04-30 05:53 config-main.cfg
Messages (5)
msg367639 - (view) Author: 左迟 (左迟) Date: 2020-04-29 10:05
Environment:
1.OS:
Windows 10 1909 Pro
2.Python version:
3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
3.Error message:
UnicodeDecodeError: 'CP_UTF8' codec can't decode byte 0xd0 in position 23: No mapping for the Unicode character exists in the target code page

How to reporduce?
Set the code page to UTF-8 in windows control pannel/region/
Type idle in the terminal hoping to launch the IDLE, but you will get the error.
msg367642 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-04-29 11:47
The uploaded .png has the traceback.  (Pasting it into the post would have been fine and a bit easier for all of us.)  The error occurred when IDLE's config tried to load the user config files, ~/.idlerc/config-xyz.cfg. (~ is usually C:/Users/yourname.)  configparser.read opens the files with the default 'encoding=None', which uses the current system default. This failed with the error given.  Either there is a byte error in one of the files or you customized IDLE with a non-ascii character before switching to utf-8, if indeed you switched.

In either case, the reading error does not appear to be an IDLE bug.  However, IDLE should catch UnicodeDecodeError, tell the user which file could not be read and how it failed, and move on as if it were not there.

Serhiy: Codec CP_UTF8 is not listed in https://docs.python.org/3.7/library/codecs.html#standard-encodings.  Should it be? Any other comments?

左迟: On my American machine, I can open Control Panel, select Clock and Region, Region, Administrative tab, and there is a button for 'Change system local...'.  It pops up a box with a checkbox "[] Beta: Use Unicode UTF8 for worldwide language support."  Is this what you meant, and/or what you did?

If the user config files were only written by IDLE, they could always be uft-8 encoded.  However, users were once told to edit by hand, and there are still cased when they do, and for some things like loading custom keysets, it is quite appropriate.
msg367644 - (view) Author: 左迟 (左迟) Date: 2020-04-29 12:53
Hi!
Thanks for your useful comment. And I'm sorry for uploading the image but not pasting it in the comment.
When I append "encoding=utf-8" to ~/.idlerc/config-main.cfg, the idle turns to be good and works well.
Yes, the "[] Beta: Use Unicode UTF8 for worldwide language support" is what I mean.
The reason why I raise this issue is there is no searching results for this error messgae.
In fact, my OS language is Chinese. And I tick the beta UTF8 option manually. It seems like that causes the IDLE crash.
Really thanks for your help!
Best Regards, Chi.
msg367703 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-04-29 21:18
I want this left open to fix IDLE exiting instead of continuing.  The original IDLE authors could not anticipate all the things that users around the world (and OS developers) might do, and we maintainers are still plugging holes as they are reported.

From the original report, I am slightly surprised that your fix worked.  Please either upload your revised config-main.cfg or paste it into a reply.  Changing it should not, that I know of, affect the reading of other .cfg files, only the subsequent loading of .py files.  Even then, it would have to end with an "[EditorWindow]" section, so that "encoding=utf-8" would be in the proper section.

(I should also check the error messaging for un-readable .py files too)
msg367739 - (view) Author: 左迟 (左迟) Date: 2020-04-30 05:53
Well, I have uploaded my ~/.idlerc/config-main.cfg. And apeeding "encodin=utf-8" is my first time to edit config-main.cfg file manually.
The content of config-main.cfg is below:
  1 [EditorWindow]
  2 font-size = 16
  3 font-bold = False
  4 encoding = utf-8
  5 font = courier new
  6
Just let me know if I could help you.
History
Date User Action Args
2022-04-11 14:59:30adminsetgithub: 84615
2020-04-30 05:53:53左迟setfiles: + config-main.cfg

messages: + msg367739
2020-04-29 21:18:49terry.reedysetstatus: closed -> open
resolution: not a bug ->
messages: + msg367703

stage: resolved -> test needed
2020-04-29 12:53:29左迟setstatus: open -> closed
versions: - Python 3.8, Python 3.9
messages: + msg367644

resolution: not a bug
stage: test needed -> resolved
2020-04-29 11:58:05terry.reedysettitle: Failed to launch IDLE in a UTF-8 code page terminal environment -> IDLE should catch user config file UnicodeDecodeError
2020-04-29 11:47:35terry.reedysettype: crash -> behavior
stage: test needed
messages: + msg367642
versions: + Python 3.8, Python 3.9
2020-04-29 10:05:36左迟create