Development

Python Unicode 에러

chbae 2023. 4. 19. 03:19
320x100
반응형

Python 코딩을 하다가 아래와 같은 에러가 나타났다. 유니코드 변환 문제이다.

Error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 13: ordinal not in range(128)

구글링의 다양한 방법이 나왔지만 아래 방법으로 문제를 해결 했다.

 

Solution

import sys;  

reload(sys);  
sys.setdefaultencoding("utf8")

 

Referencehttp://mypy.pythonblogs.com/12_mypy/archive/1253_workaround_for_python_bug_ascii_codec_cant_encode_character_uxa0_in_position_111_ordinal_not_in_range128.html

320x100