sitcon-tw / Camp2024-Drawing-Competition-Backend

A Python Turtle Judge Challenge System
Other
1 stars 2 forks source link

[Bug]: Judge Calling 出現 UTF -8 Encoding Error #32

Closed fan9704 closed 5 months ago

fan9704 commented 5 months ago

Contact Details

cxz123499@gmail.com

發生了甚麼? What happened?

發生在前端上傳程式碼中會發生 如果註解中出現中文註解,會有 UTF 編碼問題 我自己測試下來可以在檔案中的第一行加入

# -*- coding: utf-8 -*-

可以解決 可能要嘗試看看加入在 Judge 內部

OS Version

Windows

提供相關的 log 輸出 Relevant log output

SyntaxError: Non-UTF-8 code starting with '\xb3' in file C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\media\code\1\1.py on line 6, but no encoding declared; see https://python.org/dev/peps/pep-0263/ for details
Error: Command '['python', 'media/code/1/1.py', 'media/result/1/temp.ps']' returned non-zero exit status 1.
Internal Server Error: /api/submission/
Traceback (most recent call last):
  File "C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\.venv\lib\site-packages\django\core\handlers\exception.py", line 55, in inner  
    response = get_response(request)
  File "C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\.venv\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\.venv\lib\site-packages\django\views\decorators\csrf.py", line 56, in wrapper_view
    return view_func(*args, **kwargs)
  File "C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\.venv\lib\site-packages\django\views\generic\base.py", line 104, in view       
    return self.dispatch(request, *args, **kwargs)
  File "C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\.venv\lib\site-packages\rest_framework\views.py", line 509, in dispatch        
    response = self.handle_exception(exc)
  File "C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\.venv\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
    self.raise_uncaught_exception(exc)
  File "C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\.venv\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
    raise exc
  File "C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\.venv\lib\site-packages\rest_framework\views.py", line 506, in dispatch        
    response = handler(request, *args, **kwargs)
  File "C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\api\views\submission.py", line 77, in post
    score, similarity, word_count, execution_time = judge_submission(code_path, image_url, result_path)
  File "C:\Users\cxz12\PycharmProjects\Drawing-Competition-Backend\judge.py", line 105, in judge_submission
    score, similarity, word_count, execution_time = run_code(code_path, image_url, result_path)
TypeError: cannot unpack non-iterable NoneType object

行為準則 Code of Conduct

fan9704 commented 5 months ago

或者討論一下 是否要在前端的 JSON 以及給予學員的 Template 中加入這行

# -*- coding: utf-8 -*-

@burnedinthesky