AttributeError: 'NoneType' object has no attribute 'encoding'这咋解决
出现属性错误的原因就是因为 ‘label’: repo_dict[‘description’] 所读取的属性中有一个是空的,所以产生属性报错。
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)
而解决办法也很简单
for repo_dict in repo_dicts:
names.append(repo_dict['name'])
plot_dict = {
'value': repo_dict['stargazers_count'],
'label': str(repo_dict['description']),
'xlink': repo_dict['html_url']
}
plot_dicts.append(plot_dict)
只要把读取过来的属性全部转化为字符类型的即可,这样如果为空就可以显示为NONE,就不会产生报错。
根据参考资料中的段落0和段落3可以得出,出现AttributeError: 'NoneType' object has no attribute 'encoding'或者AttributeError: 'NoneType' object has no attribute 'shape'的错误可能原因是没有正确读取到数据导致变量为空的NoneType类型。因此需要检查数据路径是否正确、数据是否存在等问题。另外,根据段落9的分析,如果变量本身是NoneType类型,放入函数中就会出现以上错误,也需要检查函数输入。如果是第三方库或者包使用不当,可以查看该库或者包的官方文档并尝试修改代码使用正确的方式去调用。
对于具体的解决方案,需要看具体的代码和报错信息,无法一概而论。
self.charset是什么值
charset_by_name 这个返回了 None