Python으로 text 파일을 열어서 처리를 하려고 하는데, 이상한 데이터(예를 들면 0xff)가 읽힌다는 에러가 발생하기도 합니다.
[error] encoding : utf8, message : 'utf-8' codec can't decode byte 0xff in position 8: invalid continuation byte
이때 utf8, cp949, euc-kr등으로 변경하라는 가이드가 많이 보입니다.
제가 사용한 text 파일들은 이런 방법으로도 문제가 계속 발생했습니다.
python3의 경우, errors = ignore 옵션을 추가하면 문제가 해결되었습니다.
open(path, 'r', encoding='utf-8', errors='ignore')
관련 링크들입니다.
https://stackoverflow.com/questions/30700166/python-open-file-error
python open file error
I am trying to open some file and I know there are some errors in the file with UTF-8 encoding, so what I will do in python3 is open(fileName, 'r', errors = 'ignore') but now I need to use pyth...
stackoverflow.com
https://stackoverflow.com/questions/12468179/unicodedecodeerror-utf8-codec-cant-decode-byte-0x9c
UnicodeDecodeError: 'utf8' codec can't decode byte 0x9c
I have a socket server that is supposed to receive UTF-8 valid characters from clients. The problem is some clients (mainly hackers) are sending all the wrong kind of data over it. I can easily
stackoverflow.com
- End -
'프로그래밍 > Python' 카테고리의 다른 글
[Python] 디버깅 (0) | 2020.05.03 |
---|---|
[Python] 폴더 생성, tar 예제 (0) | 2020.05.03 |
[Python] Animation 예제 (0) | 2020.05.03 |
[Python] matplotlib 예제 (0) | 2020.05.03 |