Python : UnicodeEncodeError / 파이썬 인코딩 에러

pyscripter 2.7 에서 코딩후 run 을 해보면
아래와 같은 에러가 나면서 실행이 안됩니다.

UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 22-25: ordinal not in range(128)

여러날 고생해서 인터넷을 찾아보니 해결방법을 찾았습니다.

C:\Python27\Lib\site.py

def setencoding():
“””Set the string encoding used by the Unicode implementation. The
default is ‘ascii’, but if you’re willing to experiment, you can
change this.”””
encoding = “ascii” # Default value set by _PyUnicode_Init()
if 1: # 기존에 0 이라고 되어있는 것을 1 로 수정하면됩니다.
# Enable to support locale aware default string encodings.
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]

출처 : http://redrebel.tistory.com/archive/20130329

Leave a Reply

Your email address will not be published.