#27598 closed defect (duplicate)

Unicode problem with SageTeX

Reported by: jhpalmieri Owned by:
Priority: major Milestone: sage-duplicate/invalid/wontfix
Component: packages: standard Keywords:
Cc: Merged in:
Authors: Reviewers:
Report Upstream: N/A Work issues:
Branch: Commit:
Dependencies: Stopgaps:

Description

Running SageTeX with Python 2 on this file fails:

\documentclass{article}
\usepackage{sagetex}
\begin{document}

\begin{sageblock}
  s = "hello á goodbye"
\end{sageblock}

\end{document}

(With Python 3, I think it works.) The error occurs when running Sage:

$ sage junk.sagetex.sage
Processing Sage code for junk.tex...
Code block (line 5) begin...end
Traceback (most recent call last):
  File "junk.sagetex.sage.py", line 16, in <module>
    _st_.endofdoc()
  File "/Users/jpalmier/Desktop/Sage/git/sage/local/lib/python2.7/site-packages/sagetex.py", line 276, in endofdoc
    m.update(bytearray(line,'utf8'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 14: ordinal not in range(128)

Change History (5)

comment:1 Changed 15 months ago by jhpalmieri

The problem is with the use of the bytearray function. With Sage built with Python 2:

sage: bytearray('á')
bytearray(b'\xc3\xa1')
sage: bytearray('á', 'utf8')
---------------------------------------------------------------------------
UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-5-ed3cbd107e76> in <module>()
----> 1 bytearray('á', 'utf8')

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

With Sage built with Python 3:

sage: bytearray('á')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-c2017f20abfd> in <module>()
----> 1 bytearray('á')

TypeError: string argument without an encoding
sage: bytearray('á', 'utf8')
bytearray(b'\xc3\xa1')
Version 0, edited 15 months ago by jhpalmieri (next)

comment:2 Changed 13 months ago by dimpase

this is hopefully fixed in #27968, which includes the recently merged PR that deals with this issue.

comment:3 Changed 13 months ago by dimpase

  • Status changed from new to needs_review

please confirm that #27968 provides the fix, then this can be closed.

comment:4 Changed 13 months ago by jhpalmieri

  • Milestone changed from sage-8.8 to sage-duplicate/invalid/wontfix
  • Status changed from needs_review to positive_review

Confirmed. Marked as duplicate.

comment:5 Changed 12 months ago by chapoton

  • Resolution set to duplicate
  • Status changed from positive_review to closed
Note: See TracTickets for help on using tickets.