I’m new to GitHub classroom and just setup my first assignment (Python 3). I used input/output autograding cases for simplicity but, since I teach in Spanish, I use a lot of characters with diacritical marks [áéíóúüñ] that seems to be causing issues when running the autograder.
I get the following:
\xfa character the autograder is complaining about is the acute-accented letter u (
ú), from the word
I already have a:
# -*- coding: utf-8 -*-
directive in my code.
Any ideas? Which coding should I use for the Linux server the autograder runs on? UTF-8 works just fine in Spyder on Windows as well as in Repl.it.
From my experience the main source of encoding-related errors is running code with python 2 instead of python 3. For example, in Ubuntu 18.04 by default
python points to the 2.7.x version, while
python3 will run version 3.6+. In a more recent Ubuntu 20.04 python 2 is gone, so this shouldn’t be an issue. Autograding in GH classroom is using
ubuntu-latest, which, according to the docs, for the time being could be either 18.04 or 20.04, depending on your luck.
If you could confirm that you are using
python3 then the issue is probably in the code.
Thanks for your answer. I can confirm I am using python3. In particular, the run command is:
The problem is in the code, but it shouldn’t be a problem. It’s an issue of encoding (or code page). As you can see from line 6 in the screen capture of my original post, the line at which the run fails is:
a = eval(input("Dame un n\xfamero: "))
In the original file, the line reads:
a = eval(input("Dame un número: "))
as can be seen in the following screen capture:
The error on line 7 (and lines 11, 15 and 19, from running subsequent tests) in the screen capture of my original post is an UnicodeEncodeError: it’s trying to decode using ascii codec and failing at the letter “ú”.
The point is that it should be using utf-8 codec, not ascii. As per the following directive at the top of calculadora.py:
# -*- coding: utf-8 -*-
How can I make the autograder use the utf-8 codec?
Here’s what I ended up doing:
- I modified the .github/workflows/classroom.yml file and added an env: section with the line: LANG: C-UTF-8:
- I modified the .github/classroom/autograding.json file to prepend the run command of every test case with “LANG=en_US.utf8”:
And, finally, the tests passed (obviously, without any modification to the source file):
The file runs, characters are properly displayed… I can’t believe nobody else has had problems before me with the standard configuration of the Ubuntu machines being ASCII instead of UTF-8. I mean, Python is UTF-8 by default, isn’t it?
Now, would I have to do this again for every assignment I create to be able to properly use autograding?