最近在学习《Python编程-从入门到实践》这本书,在运行下面这段代码的时候一直报错
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)
错误提示为AttributeError: 'NoneType' object has no attribute 'decode'
经查询后将
'label':repo_dict['description']
改为
'label': str(repo_dict['description'])
str类型就正常了
报错原因: github上面有的项目没有description信息,所以repo_dict[‘description’]中有的value值为空,返回None,引起错误