본문 바로가기
프로그램

[파이썬] 에러('cp949' codec can't encode character '\u2013' in position 176: illegal multibyte sequence)

by 오디세이99 2022. 8. 22.
728x90
반응형

파일 Open 하여 Write 중 에러가 발생했습니다.

 

f = open('wiki_data.txt','w')
f.write(data)
f.close()

다음과 같이 에러가 발생했습니다.

---------------------------------------------------------------------------
UnicodeEncodeError                        Traceback (most recent call last)
Input In [21], in <cell line: 16>()
     13 f = open('wiki_data2.txt','w')
---> 16 f.write(data)
     17 f.close()

UnicodeEncodeError: 'cp949' codec can't encode character '\u2013' in position 28602: illegal multibyte sequence

 

해결 방법

- Open 시 encoding='UTF-8' 옵션을 추가해 줍니다.

f = open('wiki_data.txt','w',encoding='UTF-8')
f.write(data)
f.close()
728x90
반응형

댓글