Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grader.check() throws UnicodeDecodeError on Windows machines #380

Closed
wsepesi opened this issue Sep 8, 2021 · 7 comments · Fixed by #382
Closed

grader.check() throws UnicodeDecodeError on Windows machines #380

wsepesi opened this issue Sep 8, 2021 · 7 comments · Fixed by #382
Labels
bug Something isn't working
Milestone

Comments

@wsepesi
Copy link

wsepesi commented Sep 8, 2021

Describe the bug
I am using otter-grader to auto grade Jupyter Notebook assignments for an Intro to Data Science class, and using the given syntax for designing these type of files -- the result works perfectly on Mac, but on Windows running a cell that has a grader.check("questionName") in it throws the following UnicodeDecodeError, seemingly because open(filename) also requires an encoding argument on Windows (see this article: https://stackoverflow.com/questions/9233027/unicodedecodeerror-charmap-codec-cant-decode-byte-x-in-position-y-character). This problem also happens for grader.export()
Error:

UnicodeDecodeError                        Traceback (most recent call last)
<ipython-input-3-fe8495b0a09a> in <module>
----> 1 grader.check("q2a")

~\miniconda3\envs\cse217a\lib\site-packages\otter\check\utils.py in run_function(self, *args, **kwargs)
    130                 except Exception as e:
    131                     self._log_event(event_type, success=False, error=e)
--> 132                     raise e
    133                 else:
    134                     self._log_event(event_type, results=results, question=question, shelve_env=shelve_env)

~\miniconda3\envs\cse217a\lib\site-packages\otter\check\utils.py in run_function(self, *args, **kwargs)
    123                 try:
    124                     if event_type == EventType.CHECK:
--> 125                         question, results, shelve_env = f(self, *args, **kwargs)
    126                     else:
    127                         results = f(self, *args, **kwargs)

~\miniconda3\envs\cse217a\lib\site-packages\otter\check\notebook.py in check(self, question, global_env)
    175 
    176         # run the check
--> 177         result = check(test_path, test_name, global_env)
    178 
    179         return question, result, global_env

~\miniconda3\envs\cse217a\lib\site-packages\otter\execute\__init__.py in check(nb_or_test_path, test_name, global_env)
     44         test = OKTestFile.from_file(nb_or_test_path)
     45     else:
---> 46         test = NotebookMetadataOKTestFile.from_file(nb_or_test_path, test_name)
     47 
     48     if global_env is None:

~\miniconda3\envs\cse217a\lib\site-packages\otter\test_files\metadata_test.py in from_file(cls, path, test_name)
     72         """
     73         with open(path) as f:
---> 74             nb = json.load(f)
     75 
     76         test_spec = nb["metadata"][NOTEBOOK_METADATA_KEY]["tests"]

~\miniconda3\envs\cse217a\lib\json\__init__.py in load(fp, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
    291     kwarg; otherwise ``JSONDecoder`` is used.
    292     """
--> 293     return loads(fp.read(),
    294         cls=cls, object_hook=object_hook,
    295         parse_float=parse_float, parse_int=parse_int,

~\miniconda3\envs\cse217a\lib\encodings\cp1252.py in decode(self, input, final)
     21 class IncrementalDecoder(codecs.IncrementalDecoder):
     22     def decode(self, input, final=False):
---> 23         return codecs.charmap_decode(input,self.errors,decoding_table)[0]
     24 
     25 class StreamWriter(Codec,codecs.StreamWriter):

UnicodeDecodeError: 'charmap' codec can't decode byte 0x90 in position 398: character maps to <undefined>

To Reproduce
Steps to reproduce the behavior:

  1. Set up a notebook using the normal # BEGIN TEST syntax
  2. Access the student copy of the result of otter assign
  3. Use a Windows machine
  4. Run the import cell, then run a grader.check() cell

Expected behavior
grader.check() should mirror the behavior on Mac

Versions
I am using the following .yml to generate a conda environment. Again, these exact same versions work on Mac.

channels:
  - defaults
  - conda-forge
dependencies:
  - python=3.7
  - pip=20.3.3
  - numpy=1.19.2
  - pandas=1.2.0
  - scipy=1.5.2
  - ipython=7.19.0
  - jupyter=1.0.0
  - scikit-learn=0.23.2
  - matplotlib=3.3.2
  - seaborn=0.11.1
  - otter-grader=3.1.1
  - pillow
  - python-twitter
  - wordcloud
  - tqdm
  - scikit-image```
@wsepesi wsepesi added the bug Something isn't working label Sep 8, 2021
@chrispyles
Copy link
Member

@wsepesi I believe I've fixed this issue. Do you mind re-installing Otter from my fork as below and verifying that this fix works for you?

pip uninstall -y otter-grader
pip install git+https://github.com/chrispyles/otter-grader.git@fix-380

@chrispyles chrispyles added this to the v3.1.2 milestone Sep 9, 2021
@wsepesi
Copy link
Author

wsepesi commented Sep 9, 2021

@chrispyles It's working on my end as well, thank so you much for the prompt fix! I appreciate your work on the tool, and best wishes from the WashU CS department!

@wsepesi
Copy link
Author

wsepesi commented Sep 9, 2021

Do you have a timeline for the release of 3.1.2 by any chance?

@chrispyles
Copy link
Member

Not yet. There's another bug that I'm trying to get more info on that I'd like to include in that version if possible.

@wsepesi
Copy link
Author

wsepesi commented Sep 9, 2021

Gotcha -- if I have students trying to work on assignment this weekend, is it okay if they temporarily use the fork? There are other workarounds so no worries if not, it would just make things a bit easier for them.

@chrispyles
Copy link
Member

I was able to find and fix the other bug, so I've just released v3.1.2. (But for the record, yes, that would've been fine.)

@wsepesi
Copy link
Author

wsepesi commented Sep 10, 2021

Great, thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants