[Python Error] 'charmap' codec can't encode character '\xe3' in position 1: character maps to <undefined>

2020. 10. 31. 21:44·Error code 모음/4. Python errors
반응형

 

에러 발생 이유

대부분의 비 UTF 코덱은 유니코드 문자의 일부만 처리할 수 있으나, 

텍스트를 바이트로 변활할 때 문자가 인코딩에 정의되어 있지 않다면, 

인코딩 메서드나 함수의 errors 인수에 별도의 

처리기를 지정하지 않는 한 

UnicodeEncodeError 가 발생한다.

Traceback (most recent call last):
  File "C:/Users/Desktop/practice.py", line 7, in <module>
    print(city.encode('cp437'))
  File "C:\Users\lib\encodings\cp437.py", line 12, in encode
    return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character '\xe3' in position 1: character maps to <undefined>

 

 

해결 방법

인코딩 메서드를 사용할 때, 에러 처리기를 사용하면 된다.

# ignore : 인코딩할 수 없는 문자를 그냥 건너뛰는 것
print(city.encode('cp437', errors='ignore'))

# replace : 인코딩할 수 없는 문자를 (?) 로 치환하는 것
print(city.encode('cp437', errors='replace'))

# xmlcharrefreplace : 인코딩할 수 없는 문자를 xml 개체로 치환
print(city.encode('cp437', errors='xmlcharrefreplace'))

# ignore 

- 그냥 무시를 하기 때문에 많이 좋지 않은 방법이다

 

# replace 

- 데이터가 손실되지만, 어떤 문제가 있음을 직접 눈으로 확인할 수 있다.

 

 

위 에러 해결 방법은 

전문가를 위한 파이썬을 참고했다

반응형
저작자표시 비영리 동일조건 (새창열림)

'Error code 모음 > 4. Python errors' 카테고리의 다른 글

[Python Error] TypeError: an integer is required (got type _io.BufferedWriter)  (0) 2020.12.30
[Pythron Error] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 5: invalid continuation byte  (0) 2020.10.31
[python error] ImportError: cannot import name 'abc' from 'bson.py3compat'  (0) 2020.09.05
[python error] : _csv.reader' object is not subscriptable  (0) 2020.06.21
python error : list indices must be integers or slices, not str  (0) 2020.05.23
'Error code 모음/4. Python errors' 카테고리의 다른 글
  • [Python Error] TypeError: an integer is required (got type _io.BufferedWriter)
  • [Pythron Error] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe9 in position 5: invalid continuation byte
  • [python error] ImportError: cannot import name 'abc' from 'bson.py3compat'
  • [python error] : _csv.reader' object is not subscriptable
쟈누
쟈누
Ad astra per aspera
    반응형
  • 쟈누
    쟈누의 기록공간
    쟈누
  • 전체
    오늘
    어제
    • 분류 전체보기 (444)
      • AWS (31)
        • Glue (4)
        • S3 (1)
      • 클라우드 (0)
      • Data Engineering (37)
        • GitHub (10)
        • NiFi (11)
        • Spark (10)
        • Snowflake (0)
        • 머신러닝, AI (6)
      • 언어 (118)
        • 데이터 베이스 (42)
        • JAVA (9)
        • Python (34)
        • Java Script (15)
        • Linux (18)
      • 프로젝트, 인강 그리고 책 (30)
        • Spotify Project (7)
        • RASA chatbot Project (9)
        • Naver shopping Project (6)
        • 빅데이터를 지탱하는 기술 (8)
      • OLD (56)
        • IT 용어 사전 (13)
        • Front End (12)
        • Back End (31)
      • Error code 모음 (165)
        • 1. SQL errors (17)
        • 2. Hadoop errors (20)
        • 3. Linux Errors (14)
        • 4. Python errors (33)
        • 5. JAVA, Spring errors (41)
        • 6. Jav Script errors (10)
        • 7. Dev Tools errors (9)
        • 8. Git errors (8)
        • 9. Jenkins Errors (4)
        • 10. airflow Errors (2)
        • 11. Aws errors (7)
      • 개인 (1)
        • 책 (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 블로그 관리
    • 글쓰기
  • 링크

  • 공지사항

    • 간단한 블로그 소개
  • 인기 글

  • 태그

    Spring
    리눅스
    json
    AWS
    Git
    error
    node
    API
    python error
    linux
    MySQL
    설치
    NiFi
    Python
    에러
    install
    SQL
    자바
    파이썬
    java
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
쟈누
[Python Error] 'charmap' codec can't encode character '\xe3' in position 1: character maps to <undefined>
상단으로

티스토리툴바