Re: [問題] 用socket的recv()接收中文…

看板Python作者 (Anemos)時間16年前 (2009/02/05 15:27), 編輯推噓1(101)
留言2則, 1人參與, 最新討論串2/4 (看更多)
讓server print接收到的字串: unicode terminal: telnet client輸入"文",server收到'\xe6\x96\x87\r\n' (正常) telnet client輸入"可",server收到'\xe5\xff\xf5\xff\xfd\x06\xaf\r\n' '\xff\xfb\x06' 沒打錯,server是收到兩行字… big5 terminal: telnet client輸入"文",server收到'\xa4\xe5\r\n' (正常) telnet client輸入"可",server收到'\xa5i\r\n' (正常) pcmanx utf8: telnet client輸入"文",server收到'\xe6\x96\x87' telnet client輸入"可",server收到'\xe5\x8f\xaf' pcmanx big5: telnet client輸入"文",server收到'\xa4\xe5' telnet client輸入"可",server收到'\xa5i' pcmanx不會等按enter就會送字了,所以不會收到換行符號。 用了str.decode('utf8')的話,遇到中文就掛… 對了,是用python 2.5.2,debian的。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.137.32.135

02/05 15:45, , 1F
你傳送的時候有 str.encode('utf8')嗎?
02/05 15:45, 1F

02/05 15:45, , 2F
沒有的話會掛是很正常= =
02/05 15:45, 2F
文章代碼(AID): #19YfJpuI (Python)
文章代碼(AID): #19YfJpuI (Python)