Skip to content


Subversion checkout URL

You can clone with
Download ZIP


ipython3 traceback unicode issue from extensions #1100

juliantaylor opened this Issue · 1 comment

2 participants


ipython3 has issues when displaying context of an exception originating from an pythone extension. it works without context (plain xmode)
e.g. with pyzmq:

%xmode context
import zmq
ctx = zmq.Context()
so = ctx.socket(zmq.REQ)
#intentional error, expected AttributeError: Socket has no such option: SENT

UnicodeDecodeError                        Traceback (most recent call last)
/usr/lib/python3/dist-packages/IPython/core/ in run_code(self, code_obj)
   2545             self.CustomTB(etype,value,tb)
   2546         except:
-> 2547             self.showtraceback()
   2548         else:
   2549             outflag = 0

/usr/lib/python3/dist-packages/IPython/core/ in showtraceback(self, exc_tuple, filename, tb_offset, exception_only)
   1636                     else:
   1637                         stb = self.InteractiveTB.structured_traceback(etype,
-> 1638                                                 value, tb, tb_offset=tb_offset)
   1640                         self._showtraceback(etype, value, stb)

/usr/lib/python3/dist-packages/IPython/core/ in structured_traceback(self, etype, value, tb, tb_offset, context)
   1174         self.tb = tb
   1175         return FormattedTB.structured_traceback(
-> 1176             self, etype, value, tb, tb_offset, context)
   1178 #---------------------------------------------------------------------------

/usr/lib/python3/dist-packages/IPython/core/ in structured_traceback(self, etype, value, tb, tb_offset, context)
   1082             # Verbose modes need a full traceback

   1083             return VerboseTB.structured_traceback(
-> 1084                 self, etype, value, tb, tb_offset, context
   1085             )
   1086         else:

/usr/lib/python3/dist-packages/IPython/core/ in structured_traceback(self, etype, evalue, etb, tb_offset, context)
    878                 # This builds the names list in-place by capturing it from the

    879                 # enclosing scope.

--> 880                 for token in generate_tokens(linereader):
    881                     tokeneater(*token)
    882             except IndexError:

/usr/lib/python3.2/ in _tokenize(readline, encoding)
    391     while True:             # loop over lines in stream
    392         try:
--> 393             line = readline()
    394         except StopIteration:
    395             line = b''

/usr/lib/python3/dist-packages/IPython/core/ in linereader(file, lnum, getline)
    870             def linereader(file=file, lnum=[lnum], getline=linecache.getline):
--> 871                 line = getline(file, lnum[0])
    872                 lnum[0] += 1
    873                 return line

/usr/lib/python3.2/ in getline(filename, lineno, module_globals)
     14 def getline(filename, lineno, module_globals=None):
---> 15     lines = getlines(filename, module_globals)
     16     if 1 <= lineno <= len(lines):
     17         return lines[lineno-1]

/usr/lib/python3.2/ in getlines(filename, module_globals)
     39         return cache[filename][2]
     40     else:
---> 41         return updatecache(filename, module_globals)

/usr/lib/python3.2/ in updatecache(filename, module_globals)
    130     try:
    131         with as fp:
--> 132             lines = fp.readlines()
    133     except IOError:
    134         return []

/usr/lib/python3.2/ in decode(self, input, final)
    298         # decode input (taking the buffer into account)

    299         data = self.buffer + input
--> 300         (result, consumed) = self._buffer_decode(data, self.errors, final)
    301         # keep undecoded input until the next call

    302         self.buffer = data[consumed:]

UnicodeDecodeError: 'utf8' codec can't decode byte 0xc0 in position 96: invalid start byte
@takluyver takluyver was assigned

I've assigned this to myself to have a look at. I have a feeling I found and fixed the issue in the pure-Python 3 port I did for 0.11, so hopefully it will be an easy fix here.

@takluyver takluyver referenced this issue from a commit in takluyver/ipython
@takluyver takluyver Fix display of errors in compiled code on Python 3.
Closes gh-1100
@takluyver takluyver closed this in 411ba6a
@fperez fperez referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
@mattvonrocketstein mattvonrocketstein referenced this issue from a commit in mattvonrocketstein/ipython
@takluyver takluyver Fix display of errors in compiled code on Python 3.
Closes gh-1100
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.