2015-04-15 42 views
10

Twitch botumu Python 2.7'den Python 3.5'e taşıyorum. Aşağıdaki kodun 2. satırında a bytes like object is required not 'str' hatasını almaya devam ediyorum. [I Pain Dur Nasıl, Pragmatik Unicode veya?] Ned Batcheler en (http://bit.ly:Python - nesne gibi bir bayt gerekli, str değil

twitchdata = irc.recv(1204) 
    data = twitchdata.split(":")[1] 
    twitchuser = data.split("!")[0] 
    twitchmsg = twitchdata.split(":")[2] 
    chat = str(twitchuser) +": "+ str(twitchmsg) 
    print(chat) #prints chat to console 
+0

görün deneyin/unipain) – delnan

cevap

17

da

data = twitchdata.decode().split(":")[1] 

yerine

data = twitchdata.split(":")[1] 
+0

Bence 'decode' demek istiyorsun. Ve elbette, diğer 'split' çağrıları için de aynı şey gerekirdi, bu yüzden kod çözme, ilk satırda bir kez gerçekleşmelidir. Artı ASCII bile doğru kodlama ise soru ... – delnan

+0

Ben sadece decode() olduğunu düşünüyorum ve bence https://docs.python.org/release/3.0.1/whatsnew/3.0.html#text -vs-data-of-unicode-vs-8-bit – valentin

+0

Teşekkür ederim. Ben data = twitchdata.decode ("ascii") kullanılır. Bölünmüş (":") [1] ve bu çalıştı – spencermehta

İlgili konular