본문 바로가기
파이썬

파이썬에서 유니 코드 (비 ASCII) 문자를 처리하는 방법은 무엇입니까?

by º기록 2021. 1. 17.
반응형


File "c:\Python25\lib\httplib.py", line 711, in send
    self.sock.sendall(str) 
File "<string>", line 1, in sendall:
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xf1' in position 74: ordinal not in range(128)


 

해결 방법

 

소켓에서 바이트 집합을 읽었습니다. 문자열을 원한다면 디코딩해야합니다.

yourstring = receivedbytes.decode("utf-8") 

( utf-8 에 사용중인 인코딩으로 대체)

그런 다음 반대로 다시 보내야합니다.

outbytes = yourstring.encode("utf-8")

 

참조 페이지 https://stackoverflow.com/questions/1644640

 

 

반응형

댓글