AtrributError: ‘str‘ object has no attribute ‘decode‘解决记录方案

一、报错

Traceback (most recent call last):
  File "stream.py", line 81, in <module>
    net = load_model(f1, custom=customs_func)
  File "/home/xxx/anaconda3/envs/AAAA/lib/python3.7/site-packages/BBB/engine/saving.py", line 492, in load_wrapper
    return load_function(*args, **kwargs)
  File "/home/xxx/anaconda3/envs/AAAA/lib/python3.7/site-packages/BBB/engine/saving.py", line 584, in load_model
    model_config = json.loads(model_config.decode('utf-8'))
AttributeError: 'str' object has no attribute 'decode'

二、分析

解释:属性错误,str对象不包含‘decode’属性。
加载模型。对其解码,出现报错,是python2与python3在字符串编码上的区别。

三、解决方案

UU们提供的两种方案,个人使用第二种成功解决!
1、直接去掉解码utf8

直接去掉decode(‘utf8’)

因为,python在bytes和str两种类型转换,所需要的函数依次是encode(),decode(),这是python2与python3在返回值解码上的区别。

2.方案二:直接安装h5py

pip3 install ‘h5py<3.0.0’ -i https://pypi.tuna.tsinghua.edu.cn/simple

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
"AttributeError: 'str' object has no attribute 'decode'" 错误通常是因为字符串对象(str)没有 'decode' 属性,这是因为字符串是不可变对象,不支持解码操作。 如果你想对字符串进行解码操作,你需要使用字节字符串(bytes)对象。另外,"AttributeError: 'URLError' object has no attribute 'code'" 错误指的是 'URLError' 对象没有 'code' 属性。这可能是因为你使用了错误的属性名或者对象类型。 对于这种错误,你可以检查代码中是否正确引用了相应的属性名,并确保你使用了正确的对象类型。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [python--排错--AttributeError: 'str' object has no attribute 'decode',关于python3的字符串](https://blog.csdn.net/weixin_41357300/article/details/104846780)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [详解Python中的编码问题(encoding与decodestr与bytes)](https://download.csdn.net/download/weixin_38677227/13706348)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值