classification
Title: Add tip when encountering UnicodeDecode/EncodeError in open()
Type: Stage: resolved
Components: IO Versions: Python 3.10, Python 3.9
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: methane, serhiy.storchaka, steven.daprano, wyz23x2
Priority: normal Keywords:

Created on 2020-12-05 15:22 by wyz23x2, last changed 2021-04-14 05:17 by methane. This issue is now closed.

Messages (6)
msg382567 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-12-05 15:22
Programmers often stumble over UnicodeDecode/EncodeError during open(), and especially beginners don't know what to do.
There are lots of questions on Stackoverflow:
https://stackoverflow.com/questions/16528468/while-reading-file-on-python-i-got-a-unicodedecodeerror-what-can-i-do-to-resol
https://stackoverflow.com/questions/38186847/python-line-replace-returns-unicodeencodeerror
https://stackoverflow.com/questions/3224268/python-unicode-encode-error
https://stackoverflow.com/questions/50331257/python3-unicodeencodingerror
https://stackoverflow.com/questions/24717808/python-cant-write-to-file-unicodeencodeerror
......
Maybe a helpful tip can be added to the error message.
We have done this before:
>>> (1,)(2, 3)                                                                                                                <stdin>:1: SyntaxWarning: 'tuple' object is not callable; perhaps you missed a comma?
>>> print 3                                                                                                                     
  File "<stdin>", line 1                                                                                                          
    print 3                                                                                                                             
          ^                                                                                                                   SyntaxError: Missing parentheses in call to 'print'. Did you mean print(3)?
msg382568 - (view) Author: wyz23x2 (wyz23x2) * Date: 2020-12-05 15:23
>>> (1,)(2, 3)
<stdin>:1: SyntaxWarning: 'tuple' object is not callable; perhaps you missed a comma?
msg382572 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2020-12-05 16:01
4 of 5 linked questions do not have relation to open(). Half of them are Python 2 specific, and other half is Windows specific and should be fixed in recent Python releases on new Windows.
msg382575 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2020-12-05 16:46
"Maybe a helpful tip can be added to the error message."

What sort of helpful tip do you have in mind?

Remember that the error doesn't occur when the file is opened, but some time later.
msg382624 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2020-12-07 08:49
How do you think about PEP-597?
https://www.python.org/dev/peps/pep-0597/
msg388820 - (view) Author: Inada Naoki (methane) * (Python committer) Date: 2021-03-16 05:27
PEP 597 is accepted. May I close this?
History
Date User Action Args
2021-04-14 05:17:03methanesetstatus: open -> closed
resolution: wont fix
stage: resolved
2021-03-16 05:27:43methanesetmessages: + msg388820
2020-12-07 08:49:31methanesetnosy: + methane
messages: + msg382624
2020-12-05 16:46:53steven.dapranosetnosy: + steven.daprano
messages: + msg382575
2020-12-05 16:01:57serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg382572
2020-12-05 15:24:43wyz23x2settitle: Add tip when encountering UnicodeDecode/Encode Error in open() -> Add tip when encountering UnicodeDecode/EncodeError in open()
2020-12-05 15:23:29wyz23x2setmessages: + msg382568
2020-12-05 15:22:35wyz23x2create