카테고리 없음

Q. UnicodeDecodeError: 'cp949' codec can't decode byte 0xed in position 53: illegal multibyte sequence 해결방법은?

makeitworth 2021. 12. 14. 14:41

환경

Windows 10 Pro

python 3.8.12

 

에러 발생 상황

xml 포맷의 파일을 파이썬으로 읽어오려고, 

with open(filename, 'r') as f:

를 사용하여 코드를 작성하고 실행한 상황에서 문제가 생겼다.

 

에러 메세지

 

해결

'cp949'코덱을 decode하지 못한다고 했지만, 많은 경우 'UTF-8' 코덱으로 되어 있을 터. 일단 'UTF-8'으로 지정해 주었더니 에러가 해결되었다. 

with open(filename, 'r', encoding='UTF-8') as f: