Ask Your Question

Revision history [back]

UnicodeDecodeError when doing nothing with strings

I am attempting to create a function which increments a Gray code count, while returning which bit was flipped. I am implementing this in C with a Cython wrapper to be able to access it in Sage.

On the Sage command line, I am trying to load this Cython file:

cdef extern from "gray_2.c": 
    long next_gray_code(long* x, long* parity)

With this C file:

long next_gray_code(long* x, long* parity) {
            y = -(*x)&(*x);
            *x = (*x)^(y << 1);
            return log2(y) + 1;            }

And I am getting this error:

    Compiling ./gray.spyx...
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in run_code(self, code_obj, result)
   2896             if result is not None:
   2897                 result.error_in_exec = sys.exc_info()[1]
-> 2898             self.showtraceback()
   2899         else:
   2900             outflag = 0

/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in showtraceback(self, exc_tuple, filename, tb_offset, exception_only)
   1822                     except Exception:
   1823                         stb = self.InteractiveTB.structured_traceback(etype,
-> 1824                                             value, tb, tb_offset=tb_offset)
   1825 
   1826                     self._showtraceback(etype, value, stb)

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1404         self.tb = tb
   1405         return FormattedTB.structured_traceback(
-> 1406             self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1407 
   1408 

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1312             # Verbose modes need a full traceback
   1313             return VerboseTB.structured_traceback(
-> 1314                 self, etype, value, tb, tb_offset, number_of_lines_of_context
   1315             )
   1316         else:

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, evalue, etb, tb_offset, number_of_lines_of_context)
   1162 
   1163         formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
-> 1164                                                                tb_offset)
   1165 
   1166         colors = self.Colors  # just a shorthand + quicker name lookup

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in format_exception_as_a_whole(self, etype, evalue, etb, number_of_lines_of_context, tb_offset)
   1111             return ""
   1112 
-> 1113         last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records)
   1114 
   1115         frames = self.format_records(records, last_unique, recursion_repeat)

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in find_recursion(etype, value, records)
    453     # quarter of the traceback (250 frames by default) is repeats, and find the
    454     # first frame (from in to out) that looks different.
--> 455     if not is_recursion_error(etype, value, records):
    456         return len(records), 0
    457 

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in is_recursion_error(etype, value, records)
    439     # a recursion error.
    440     return (etype is recursion_error_type) \
--> 441            and "recursion" in str(value).lower() \
    442            and len(records) > 500
    443 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1542: ordinal not in range(128)

Which makes no sense to me since nothing I am doing has anything to do with strings, nor am I using anything but ascii characters in my code files (also, the trace is unhelpful since none of the referenced functions are in my code). What is going on here and how do I fix it?

UnicodeDecodeError when doing nothing with strings

I am attempting to create a function which increments a Gray code count, while returning which bit was flipped. I am implementing this in C with a Cython wrapper to be able to access it in Sage.

On the Sage command line, I am trying to load this Cython file:

cdef extern from "gray_2.c": 
    long next_gray_code(long* x, long* parity)

With this C file:

long next_gray_code(long* x, long* parity) {
            y = -(*x)&(*x);
            *x = (*x)^(y << 1);
            return log2(y) + 1;            }

And I am getting this error:

    Compiling ./gray.spyx...
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in run_code(self, code_obj, result)
   2896             if result is not None:
   2897                 result.error_in_exec = sys.exc_info()[1]
-> 2898             self.showtraceback()
   2899         else:
   2900             outflag = 0

/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in showtraceback(self, exc_tuple, filename, tb_offset, exception_only)
   1822                     except Exception:
   1823                         stb = self.InteractiveTB.structured_traceback(etype,
-> 1824                                             value, tb, tb_offset=tb_offset)
   1825 
   1826                     self._showtraceback(etype, value, stb)

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1404         self.tb = tb
   1405         return FormattedTB.structured_traceback(
-> 1406             self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1407 
   1408 

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1312             # Verbose modes need a full traceback
   1313             return VerboseTB.structured_traceback(
-> 1314                 self, etype, value, tb, tb_offset, number_of_lines_of_context
   1315             )
   1316         else:

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, evalue, etb, tb_offset, number_of_lines_of_context)
   1162 
   1163         formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
-> 1164                                                                tb_offset)
   1165 
   1166         colors = self.Colors  # just a shorthand + quicker name lookup

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in format_exception_as_a_whole(self, etype, evalue, etb, number_of_lines_of_context, tb_offset)
   1111             return ""
   1112 
-> 1113         last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records)
   1114 
   1115         frames = self.format_records(records, last_unique, recursion_repeat)

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in find_recursion(etype, value, records)
    453     # quarter of the traceback (250 frames by default) is repeats, and find the
    454     # first frame (from in to out) that looks different.
--> 455     if not is_recursion_error(etype, value, records):
    456         return len(records), 0
    457 

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in is_recursion_error(etype, value, records)
    439     # a recursion error.
    440     return (etype is recursion_error_type) \
--> 441            and "recursion" in str(value).lower() \
    442            and len(records) > 500
    443 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1542: ordinal not in range(128)

Which makes no sense to me since nothing I am doing has anything to do with strings, nor am I using anything but ascii characters in my code files (also, the trace is unhelpful since none of the referenced functions are in my code). What is going on here and how do I fix it?

UnicodeDecodeError when doing nothing with strings

I am attempting to create a function which increments a Gray code count, while returning which bit was flipped. I am implementing this in C with a Cython wrapper to be able to access it in Sage.

On the Sage command line, I am trying to load this Cython file:

cdef extern from "gray_2.c": 
    long next_gray_code(long* x, long* parity)

With this C file:

long next_gray_code(long* x, long* parity) {
            y = -(*x)&(*x);
            *x = (*x)^(y << 1);
            return log2(y) + 1;            }

And I am getting this error:

    Compiling ./gray.spyx...
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in run_code(self, code_obj, result)
   2896             if result is not None:
   2897                 result.error_in_exec = sys.exc_info()[1]
-> 2898             self.showtraceback()
   2899         else:
   2900             outflag = 0

/usr/lib/python2.7/dist-packages/IPython/core/interactiveshell.pyc in showtraceback(self, exc_tuple, filename, tb_offset, exception_only)
   1822                     except Exception:
   1823                         stb = self.InteractiveTB.structured_traceback(etype,
-> 1824                                             value, tb, tb_offset=tb_offset)
   1825 
   1826                     self._showtraceback(etype, value, stb)

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1404         self.tb = tb
   1405         return FormattedTB.structured_traceback(
-> 1406             self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1407 
   1408 

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, value, tb, tb_offset, number_of_lines_of_context)
   1312             # Verbose modes need a full traceback
   1313             return VerboseTB.structured_traceback(
-> 1314                 self, etype, value, tb, tb_offset, number_of_lines_of_context
   1315             )
   1316         else:

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in structured_traceback(self, etype, evalue, etb, tb_offset, number_of_lines_of_context)
   1162 
   1163         formatted_exception = self.format_exception_as_a_whole(etype, evalue, etb, number_of_lines_of_context,
-> 1164                                                                tb_offset)
   1165 
   1166         colors = self.Colors  # just a shorthand + quicker name lookup

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in format_exception_as_a_whole(self, etype, evalue, etb, number_of_lines_of_context, tb_offset)
   1111             return ""
   1112 
-> 1113         last_unique, recursion_repeat = find_recursion(orig_etype, evalue, records)
   1114 
   1115         frames = self.format_records(records, last_unique, recursion_repeat)

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in find_recursion(etype, value, records)
    453     # quarter of the traceback (250 frames by default) is repeats, and find the
    454     # first frame (from in to out) that looks different.
--> 455     if not is_recursion_error(etype, value, records):
    456         return len(records), 0
    457 

/usr/lib/python2.7/dist-packages/IPython/core/ultratb.pyc in is_recursion_error(etype, value, records)
    439     # a recursion error.
    440     return (etype is recursion_error_type) \
--> 441            and "recursion" in str(value).lower() \
    442            and len(records) > 500
    443 

UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 1542: ordinal not in range(128)

Which makes no sense to me since nothing I am doing has anything to do with strings, nor am I using anything but ascii characters in my code files (also, the trace is unhelpful since none of the referenced functions are in my code). What is going on here and how do I fix it?