본문 바로가기
TIL/Error해결사

[Django : cp949] UnicodeDecodeError 해결

by Eungzy 2021. 4. 6.
728x90

| 에러명 :

[Django 에러]

UnicodeDecodeError: 'cp949' codec can't decode byte 0xe2 in position 9735: illegal multibyte sequence

(+)

[웹브라우저]  A server error occurred. Please contact the administrator. 에러 발생

 

 

 

 

 

 

| 해결방법 : 

가상환경(venv) 폴더에서 Lib\site-packages\django\views\debug.py 수정

 

 

[기존]

def get_traceback_html(self):
    """Return HTML version of debug 500 HTTP error page."""
    with Path(CURRENT_DIR, 'templates', 'technical_500.html').open() as fh:
        t = DEBUG_ENGINE.from_string(fh.read())
    c = Context(self.get_traceback_data(), use_l10n=False)
    return t.render(c)

 

 

[수정후 : open() 안에 encoding="utf-8" 추가 기입]

def get_traceback\_html(self): 
    """Return HTML version of debug 500 HTTP error page.""" 
    with Path(CURRENT_DIR, 'templates', 'technical_500.html').open(encoding="utf-8") as fh: 
        t = DEBUG\_ENGINE.from_string(fh.read()) 
    c = Context(self.get_traceback_data(), use_l10n=False) 
    return t.render(c) 

 

 

| 위의 코드를 추가 기입하고 가상환경 활성화를 다시 껐다 키고 나서 해당 브라우저를 확인해보면, 

html 상에서 오류를 발생시키는 문제의 code를 알려준다. Error Tracking과 같은 역할을 한다고  볼 수 있다.

 

 

 

 

728x90

댓글