Subject: 23.1; UnicodeEncodeError in python-shell

From: Max Arnold <[email-masked]>
Date: Mon, 29 Mar 2010 11:38:09 +0700

When python shell invoked via C-c C-c, its stdout encoding is set to None and unicode
characters can not be printed. Simple test case (0xA9 should produce unicode symbol (c) ):

1. Invoke python shell manually:

M-x python-shell
>>> print u'\xA9'
©

2. And this is how to trigger the error: close python shell opened at step (1), create
new buffer containing the same print command, switch it to python-mode and press
C-c C-c (python-send-buffer). Spawned python shell will show a traceback:

>>> Traceback (most recent call last):
  File "/tmp/py5308nvC", line 1, in <module>
    print u'\xA9'
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa9' in position 0: ordinal not in range(128)

Emacs was running with -nw mode in rxvt-unicode terminal, system-wide LANG is set
to ru_RU.UTF-8. On step (1) sys.stdout.encoding is UTF-8, on step (2) it is None.

The same issue was found using python-mode.el (https://bugs.launchpad.net/python-mode/+bug/550661).
For more details see this thread: http://lists.gnu.org/archive/html/help-gnu-emacs/2010-03/msg00233.html

In GNU Emacs 23.1.1 (i686-pc-linux-gnu, GTK+ Version 2.14.7)
 of 2009-12-15 on bbone
configured using `configure  '--prefix=/usr' '--build=i686-pc-linux-gnu'
'--host=i686-pc-linux-gnu' '--mandir=/usr/share/man' '--infodir=/usr/share/info'
'--datadir=/usr/share' '--sysconfdir=/etc' '--localstatedir=/var/lib'
'--program-suffix=-emacs-23' '--infodir=/usr/share/info/emacs-23'
'--with-sound' '--with-x' '--with-toolkit-scroll-bars' '--without-gif'
'--without-jpeg' '--without-png' '--without-rsvg' '--without-tiff'
'--without-xpm' '--with-xft' '--without-libotf' '--without-m17n-flt'
'--with-x-toolkit=gtk' '--without-hesiod' '--without-kerberos'
'--without-kerberos5' '--with-gpm' '--with-dbus' 'build_alias=i686-pc-linux-gnu'
'host_alias=i686-pc-linux-gnu' 'CFLAGS=-march=i686 -O2 -pipe' 'LDFLAGS=-Wl,-O1''

Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: ru_RU.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default-enable-multibyte-characters: t

Major mode: Lisp Interaction

Minor modes in effect:
  shell-dirtrack-mode: t
  show-paren-mode: t
  iswitchb-mode: t
  global-hl-line-mode: t
  ergoemacs-mode: t
  delete-selection-mode: t
  tooltip-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  global-auto-composition-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
ESC a r e p o TAB r t - e TAB RET

Recent messages:
("emacs")
Loading ~/.emacs.d/ergoemacs-mode/5.1/ergoemacs-mode (compiled; note, source file is newer)...
Loading functions...done
Loading ergoemacs-unbind...done
Loading ergoemacs-layout-us...done
Loading ~/.emacs.d/ergoemacs-mode/5.1/ergoemacs-mode (compiled; note, source file is newer)...done
Ido mode enabled [3 times]
For information about GNU Emacs and the GNU system, type C-h C-a.
Making completion list...