ipython/ipython
在 GitHub 查看ipython UnicodeEncodeError when providing unicode char to "os.read(0,1)"
Open
#11,615 创建于 2019年2月21日
bughelp wanted
描述
I recently started playing with IPython and found a case where it exists with an "UnicodeEncodeError" error. I confirmed the issue exist on the latest version. See how to reproduce / error bellow.
Note that I do expect an error to be raised by 'os.read()', however I don't think IPython itself should exit.
vagrant@debian-9:~$ ipython
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.3.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import os; os.read(0,1)
a
Out[1]: b'a'
In [2]:
In [2]: import os; os.read(0,1)
ab
Out[2]: b'a'
In [3]: b
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-3-89e6c98d9288> in <module>
----> 1 b
NameError: name 'b' is not defined
In [4]: import os; os.read(0,1)
日
Out[4]: b'\xe6'
In [5]: ??
Traceback (most recent call last):
File "/home/vagrant/.local/bin/ipython3", line 11, in <module>
sys.exit(start_ipython())
File "/home/vagrant/.local/lib/python3.5/site-packages/IPython/__init__.py", line 125, in start_ipython
return launch_new_instance(argv=argv, **kwargs)
File "/home/vagrant/.local/lib/python3.5/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/home/vagrant/.local/lib/python3.5/site-packages/IPython/terminal/ipapp.py", line 356, in start
self.shell.mainloop()
File "/home/vagrant/.local/lib/python3.5/site-packages/IPython/terminal/interactiveshell.py", line 498, in mainloop
self.interact()
File "/home/vagrant/.local/lib/python3.5/site-packages/IPython/terminal/interactiveshell.py", line 489, in interact
self.run_cell(code, store_history=True)
File "/home/vagrant/.local/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2843, in run_cell
raw_cell, store_history, silent, shell_futures)
File "/home/vagrant/.local/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2863, in _run_cell
if self.should_run_async(raw_cell):
File "/home/vagrant/.local/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2901, in should_run_async
return _should_be_async(cell)
File "/home/vagrant/.local/lib/python3.5/site-packages/IPython/core/async_helpers.py", line 152, in _should_be_async
compile(cell, "<>", "exec")
UnicodeEncodeError: 'utf-8' codec can't encode character '\udc97' in position 0: surrogates not allowed
If you suspect this is an IPython bug, please report it at:
https://github.com/ipython/ipython/issues
or send an email to the mailing list at ipython-dev@python.org
You can print a more detailed traceback right now with "%tb", or use "%debug"
to interactively debug it.
Extra-detailed tracebacks for bug-reporting purposes can be enabled via:
%config Application.verbose_crash=True
Using the python interactive mode, following happens:
vagrant@debian-9:~$ python
Python 3.5.3 (default, Sep 27 2018, 17:25:39)
[GCC 6.3.0 20170516] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os; os.read(0,1)
a
b'a'
>>>
>>> import os; os.read(0,1)
ab
b'a'
>>> b
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>> import os; os.read(0,1)
日
b'\n'
>>> import os; os.read(0,1)
日本語
b'\xe6'
>>> 本語
File "<stdin>", line 0
^
SyntaxError: 'utf-8' codec can't decode byte 0x97 in position 0: invalid start byte
>>>