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

简介: 成功解决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


image.png


相关文章
|
2月前
|
TensorFlow 算法框架/工具 Python
【Tensorflow 2】解决'Tensor' object has no attribute 'numpy'
解决'Tensor' object has no attribute 'numpy'
43 3
|
2月前
|
API C++ Python
【Azure 应用服务】Python fastapi Function在Azure中遇见AttributeError异常(AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async')
【Azure 应用服务】Python fastapi Function在Azure中遇见AttributeError异常(AttributeError: 'AsgiMiddleware' object has no attribute 'handle_async')
|
3月前
|
并行计算 Serverless API
函数计算操作报错合集之出现 "AttributeError: 'NoneType' object has no attribute 'pop'" 错误,是什么原因
在使用函数计算服务(如阿里云函数计算)时,用户可能会遇到多种错误场景。以下是一些常见的操作报错及其可能的原因和解决方法,包括但不限于:1. 函数部署失败、2. 函数执行超时、3. 资源不足错误、4. 权限与访问错误、5. 依赖问题、6. 网络配置错误、7. 触发器配置错误、8. 日志与监控问题。
|
2月前
|
TensorFlow API 算法框架/工具
【Tensorflow+keras】解决使用model.load_weights时报错 ‘str‘ object has no attribute ‘decode‘
python 3.6,Tensorflow 2.0,在使用Tensorflow 的keras API,加载权重模型时,报错’str’ object has no attribute ‘decode’
35 0
|
3月前
|
Python
【Python】已解决:(Python xlwt写入Excel报错)AttributeError: ‘function’ object has no attribute ‘font’
【Python】已解决:(Python xlwt写入Excel报错)AttributeError: ‘function’ object has no attribute ‘font’
48 0
|
5月前
|
Java
Java Object 类
5月更文挑战第16天
|
2月前
|
Java
【Java基础面试二十】、介绍一下Object类中的方法
这篇文章介绍了Java中Object类的常用方法,包括`getClass()`、`equals()`、`hashCode()`、`toString()`、`wait()`、`notify()`、`notifyAll()`和`clone()`,并提到了不推荐使用的`finalize()`方法。
【Java基础面试二十】、介绍一下Object类中的方法
|
7天前
|
Python
类与面向对象编程(Object-Oriented Programming, OOP)
类与面向对象编程(Object-Oriented Programming, OOP)
13 0
|
2月前
|
前端开发 Java 编译器
【前端学java】java中的Object类和前端中的Object有什么区别(9)
【8月更文挑战第10天】java中的Object类和前端中的Object有什么区别
33 0
【前端学java】java中的Object类和前端中的Object有什么区别(9)
|
2月前
|
算法 Java
12 Java常用类(一)(内部类+object类+包装类)
12 Java常用类(一)(内部类+object类+包装类)
29 5
下一篇
无影云桌面