test: UnicodeDecodeError is thrown when the outputs contain non-Unicode
See original GitHub issueWhen the program to be tested prints non-Unicode strings, oj raises UnicodeDecodeError.
This often happens if you write strange languages, e.g. code golf with perl, brainfuck, etc.
This happens on both of WSL and native Ubuntu.
$ oj --version
online-judge-tools 7.3.0
$ cat main.py
#!/usr/bin/env python3
import sys
sys.stdout.buffer.write(b'\xff')
$ oj t -c 'python3 main.py'
[*] 10 cases found
[*] sample-1
Traceback (most recent call last):
File "/home/ubuntu/.local/bin/oj", line 11, in <module>
sys.exit(main())
File "/home/ubuntu/.local/lib/python3.6/site-packages/onlinejudge/_implementation/main.py", line 297, in main
run_program(namespace, parser=parser)
File "/home/ubuntu/.local/lib/python3.6/site-packages/onlinejudge/_implementation/main.py", line 276, in run_program
test(args)
File "/home/ubuntu/.local/lib/python3.6/site-packages/onlinejudge/_implementation/command/test.py", line 218, in test
history += [test_single_case(name, paths['in'], paths.get('out'), args=args)]
File "/home/ubuntu/.local/lib/python3.6/site-packages/onlinejudge/_implementation/command/test.py", line 142, in test_single_case
answer = (info['answer'] or b'').decode() # type: str
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
UnicodeDecodeError with 1.3.1 and python2.7 #816 - GitHub
So the problem is caused by mixing unicode and 8-bit str output in a test that fails. StringIO code contains this comment: The...
Read more >How to fix: "UnicodeDecodeError: 'ascii' codec can't decode ...
UnicodeDecodeError : 'ascii' codec can't decode byte generally happens when you try to convert a Python 2.x str that contains non-ASCII to a...
Read more >Bug #69988 “UnicodeDecodeError crack in doctest”
Putting this in a doctest will result in an UnicodeDecodeError when running it: Unicode crack: >>> print u'abc' abc. >>> print u'\xe9'.encode('utf-8')
Read more >Overcoming frustration: Correctly using unicode in python2
Sending the wrong value here will lead to a UnicodeError being thrown when the string contains non-ASCII characters. Note. There is one mitigating...
Read more >Fix Python UnicodeEncodeError: 'ascii' codec can't encode ...
A very common Python error that is raised when working with unicode characters is the UnicodeEncodeError . UnicodeEncodeError: 'ascii' codec can't encode ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I got it now.
I think
UnicodeDecodeErroris kind message for users in order to prevent them from WA.We can change the code to
but I can’t judge if that modification is good or not…
For example, a code
a=-1;main(){write(1,&a,3);}of C language prints non-Unicode.Of course, as far as I know, there are no problems whose correct answer contains non-Unicode. But wrong answers which we may write print non-Unicode. About the example above, if it were
a=4407873;main(){write(1,&a,3);}, it would print an ASCII lettersABC. We sometimes use such techniques, and print non-Unicode unintentionally.