ipython crash on wrong encoding #1777

Closed
buzmakov opened this Issue May 28, 2012 · 4 comments

3 participants

@buzmakov

Python 2.7.3 (default, Apr 20 2012, 22:39:59)
Type "copyright", "credits" or "license" for more information.

IPython 0.13.dev -- An enhanced Interactive Python.

In [1]: echo Äýí | iconv -f utf8 -t cp1252 | iconv -f cp1251
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 9, in
load_entry_point('ipython==0.13.dev', 'console_scripts', 'ipython')()
File "/usr/local/lib/python2.7/dist-packages/IPython/frontend/terminal/ipapp.py", line 408, in launch_new_instance
app.start()
File "/usr/local/lib/python2.7/dist-packages/IPython/frontend/terminal/ipapp.py", line 382, in start
self.shell.mainloop()
File "/usr/local/lib/python2.7/dist-packages/IPython/frontend/terminal/interactiveshell.py", line 424, in mainloop
self.interact(display_banner=display_banner)
File "/usr/local/lib/python2.7/dist-packages/IPython/frontend/terminal/interactiveshell.py", line 543, in interact
self.run_cell(source_raw, store_history=True)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2557, in run_cell
self.logger.log(cell, raw_cell)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/logger.py", line 181, in log
self.log_write(line_ori)
File "/usr/local/lib/python2.7/dist-packages/IPython/core/logger.py", line 195, in log_write
write(data)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-7: ordinal not in range(128)

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@scipy.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

@fperez
IPython member

Could you please try to reproduce it with git master? I just tested and it works fine on my system, producing the expected SyntaxError:

In [1]: echo Äýí | iconv -f utf8 -t cp1252 | iconv -f cp1251
  File "<ipython-input-1-dd4f9244223f>", line 1
    echo Äýí | iconv -f utf8 -t cp1252 | iconv -f cp1251
         ^
SyntaxError: invalid syntax
@buzmakov

Ok, I found right error case, 1-st start logging , 2-nd start this strange command:

In [1]: %logstart -r t1.log
Activating auto-logging. Current session state plus future input saved.
Filename       : t1.log
Mode           : backup
Output logging : False
Raw input log  : True
Timestamping   : False
State          : active

In [2]: echo Äýí | iconv -f utf8 -t cp1252 | iconv -f cp1251
Traceback (most recent call last):
  File "/usr/local/bin/ipython", line 9, in <module>
    load_entry_point('ipython==0.13.dev', 'console_scripts', 'ipython')()
  File "/usr/local/lib/python2.7/dist-packages/IPython/frontend/terminal/ipapp.py", line 408, in launch_new_instance
    app.start()
  File "/usr/local/lib/python2.7/dist-packages/IPython/frontend/terminal/ipapp.py", line 382, in start
    self.shell.mainloop()
  File "/usr/local/lib/python2.7/dist-packages/IPython/frontend/terminal/interactiveshell.py", line 424, in mainloop
    self.interact(display_banner=display_banner)
  File "/usr/local/lib/python2.7/dist-packages/IPython/frontend/terminal/interactiveshell.py", line 543, in interact
    self.run_cell(source_raw, store_history=True)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/interactiveshell.py", line 2557, in run_cell
    self.logger.log(cell, raw_cell)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/logger.py", line 181, in log
    self.log_write(line_ori)
  File "/usr/local/lib/python2.7/dist-packages/IPython/core/logger.py", line 195, in log_write
    write(data)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-7: ordinal not in range(128)

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@scipy.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

@takluyver
IPython member

"Doctor, it hurts when I do this"
"Don't do that"

;-)

I'll try to see if there's anything we can do about it, though.

@takluyver
IPython member

See pull request #1792

@takluyver takluyver added a commit that closed this issue May 31, 2012
@takluyver takluyver Make logging unicode-aware
Closes gh-1777
0eeff21
@takluyver takluyver closed this in 0eeff21 May 31, 2012
@mattvonrocketstein mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this issue Nov 3, 2014
@takluyver takluyver Make logging unicode-aware
Closes gh-1777
b98d851
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment