天天看點

成功解決AttributeError: ‘str‘ object has no attribute ‘decode‘

解決問題

AttributeError: 'str' object has no attribute 'decode'

解決思路

根據問題提示,意思是,屬性錯誤:“str”對象沒有屬性“decode”

python3.5和Python2.7在套接字傳回值解碼上的差別

python在bytes和str兩種類型轉換,所需要的函數依次是encode(),decode()

解決方法

T1、直接去掉

直接去掉decode('utf8')

tips:str通過encode()方法可以編碼為指定的bytes。反過來,當從網絡或磁盤上讀取了位元組流,那麼讀到的資料就是bytes。要把bytes變為str,就需要用decode()方法。反之,則使用encode()方法即可!

T2、衆多網友好評的建議

謝謝 improve100 網友提供的建議!

pip install 'h5py<3.0.0' -i

https://pypi.tuna.tsinghua.edu.cn/simple
成功解決AttributeError: ‘str‘ object has no attribute ‘decode‘