看板 Python 關於我們 聯絡資訊
我又做了新的測試: 程式碼: =============================================== # -*- coding: big5 -*- import telnetlib tn = telnetlib.Telnet('ptt.cc') s = tn.read_until(b"ptt3") print(s) =============================================== 會印出ptt的首頁畫面 但改成read_until(b"請輸入代號"),就不行,程式碼: =============================================== # -*- coding: big5 -*- import telnetlib tn = telnetlib.Telnet('ptt.cc') s = tn.read_until(b"請輸入代號") print(s) =============================================== 會顯示錯誤:『bytes can only contain ASCII literal characters.』 看read_until的文件,他接受的參數是byte string,所以應把字串轉成byte string 但看程式碼第一行是用big5 是不是指字串:『請輸入代號』已經是big5編碼 所以要想辦法把big5 轉成byte string ? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.200.46.75
icycandle:等等,你是用python2還是python3? 11/19 19:11
peanut97:python3 ~ 11/19 19:14
※ 編輯: peanut97 來自: 60.248.161.28 (11/19 19:14)