# SageTeX UnicodeDecodeError

Hello, Sage community. I've been writing a book with the help of SageTeX. Until yesterday, I was working with SageMath v8.6, and everything work perfectly. Today I downloaded SageMath v8.7 binary for Linux, and replaced the corresponding SageTeX files. But when I tried to compile the book, suddenly I receive an error message:

Traceback (most recent call last):

File "book.sagetex.sage.py", line 5158, in <module>

_st_.endofdoc()

File "/SageMath/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 29: ordinal not in range(128)

The only difference from yesterday is the new version of SageMath. Can somebody explain/help me with this matter?

edit retag close merge delete

What is the encoding of your LaTeX source file ? Windows' default of Latin1 is a source of endless problems.

• Try to specify UTF-8 as your default encoding for everythng.

• Similarly, at the top of your Sage/Python snippets, try placing # -*- coding: utf-8 -*- to clarify..

HTH,

( 2019-04-02 08:56:09 -0600 )edit

I am using Linux Ubuntu. My editor (TeXstudio) is using UTF-8 encoding, and I am also using the "utf8" option for the "inputenc" package. The fist line of my "book.sagetex.sage" file is

## -*- encoding: utf-8 -*-


However, I could reduce the problem to the fact of using accented Spanish words; if I delete the accents, the problem disappears. However, with SageMath v8.6, I didn't have that problem.

By the way,the command sys.getdefaultencoding() returns 'ascii'. So I updated my locales to use UTF-8, but nothing changes.

( 2019-04-02 09:19:48 -0600 )edit

However, with SageMath v8.6

Therefore it's a new problem. This bug should be reported on Trac (or, if you can't access trac, on sage-support and/or sage-release...).

Did you restart your session (or reboot) ?

( 2019-04-02 12:29:30 -0600 )edit

Sort by » oldest newest most voted

I agree with the comments that it looks like a bug in SageTeX. I opened https://trac.sagemath.org/ticket/27598.

In the file /SageMath/local/lib/python2.7/site-packages/sagetex.py, try replacing the line "m.update(bytearray(line,'utf8'))" with "m.update(line)". Does that fix it?

(In general this is probably not the right thing to do. I think it will work with Python 2 but not Python 3, but if your Sage is built with Python 2, the default, it could work.)

more

Thanks, this fixed the problem for me too. I had multiple sagetex.py lying around in my filesystem, and I needed to change it in only one of them (the others were still with the correct "m.update(line)"

( 2019-08-31 04:06:59 -0600 )edit

Hello.

Thank you for your answers. Indeed, as indicated by John Palmieri, the error seems to happen due to the new line m.update(bytearray(line,'utf8')). If replaced with m.update(line)(i.e., the old behavior), the problem is fixed. Thank you for reporting the issue on trac.sagemath.org.

Coincidentally, before reading this, I could zero in on the problem, so I filed a new issue report for SageTeX (https://github.com/sagemath/sagetex/i...). I will mention the report by John.

Thank you very much for your help, Emmanuel and John.

more

Hello, Thank you all very much for your help! I had exactly the same problem and all seams to work fine for me now!

Marcus

more