Python 3.6解决报错:'NoneType' object has no attribute 'decode'的办法

本文介绍了一种常见的Python编程错误——'NoneType' object has no attribute 'decode'的解决方案。通过将repo_dict['description']强制转换为字符串类型,可以避免因读取None值而导致的属性调用错误。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

for repo_dict in repo_dicts:
    names.append(repo_dict['name'])
    plot_dict={'value':repo_dict['stargazers_count'],
               'label':repo_dict['description'],
               'xlink':repo_dict['html_url'],
               }
    plot_dicts.append(plot_dict)

在运行上面代码时,出现了

'NoneType' object has no attribute 'decode'

的错误,查阅资料后发现只要将

'label':repo_dict['description']

改为:

'label': str(repo_dict['description'])

就可以解决问题了

作者:hhhaoyi815
来源:优快云
原文:https://blog.youkuaiyun.com/weixin_42427638/article/details/80640817
版权声明:本文为博主原创文章,转载请附上博文链接!

Exception in thread Thread-1 (_readerthread): Traceback (most recent call last): File "C:\Users\dengm\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1075, in _bootstrap_inner self.run() File "C:\Users\dengm\AppData\Local\Programs\Python\Python312\Lib\threading.py", line 1012, in run self._target(*self._args, **self._kwargs) File "C:\Users\dengm\AppData\Local\Programs\Python\Python312\Lib\subprocess.py", line 1599, in _readerthread buffer.append(fh.read()) ^^^^^^^^^ UnicodeDecodeError: &#39;gbk&#39; codec can&#39;t decode byte 0xad in position 159: illegal multibyte sequence Traceback (most recent call last): File "E:\接单\逆向\cba.py", line 34, in <module> ret = js.call("a5e", resp.text.strip(&#39;"&#39;)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\package\.venv\Lib\site-packages\execjs\_abstract_runtime_context.py", line 37, in call return self._call(name, *args) ^^^^^^^^^^^^^^^^^^^^^^^ File "D:\package\.venv\Lib\site-packages\execjs\_external_runtime.py", line 92, in _call return self._eval("{identifier}.apply(this, {args})".format(identifier=identifier, args=args)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\package\.venv\Lib\site-packages\execjs\_external_runtime.py", line 78, in _eval return self.exec_(code) ^^^^^^^^^^^^^^^^ File "D:\package\.venv\Lib\site-packages\execjs\_abstract_runtime_context.py", line 18, in exec_ return self._exec_(source) ^^^^^^^^^^^^^^^^^^^ File "D:\package\.venv\Lib\site-packages\execjs\_external_runtime.py", line 88, in _exec_ return self._extract_result(output) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\package\.venv\Lib\site-packages\execjs\_external_runtime.py", line 156, in _extract_result output = output.replace("\r\n", "\n").replace("\r", "\n") ^^^^^^^^^^^^^^ AttributeError: &#39;NoneType&#39; object has no attribute &#39;replace&#39;
最新发布
07-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值