gpt4 book ai didi

python-3.x - 属性错误 : 'NoneType' object has no attribute 'decode'

转载 作者:行者123 更新时间:2023-12-03 09:48:59 26 4
gpt4 key购买 nike

names, plot_dicts = [], []
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['owner']['html_url'],
}
plot_dicts.append(plot_dict)

my_style = LS('#333366', base_style=LCS)
chart = pygal.Bar(style=my_style, x_label_rotation=45, show_legend=False)
chart.title = 'Most-Stared Python Project On Github'
chart.x_labels = names
chart.add('', plot_dicts)

chart.render_to_file('new_repos.svg')

*如果我运行这个,会有错误。
Traceback (most recent call last):
File "new_repos.py", line 54, in <module>
chart.render_to_file('new_repos.svg')
File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\public.py", line 114, in render_to_file
f.write(self.render(is_unicode=True, **kwargs))
File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\public.py", line 52, in render
self.setup(**kwargs)
File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\base.py", line 217, in setup
self._draw()
File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\graph.py", line 933, in _draw
self._plot()
File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\bar.py", line 146, in _plot
self.bar(serie)
File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\graph\bar.py", line 116, in bar
metadata)
File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\util.py", line 234, in decorate
metadata['label'])
File "C:\Users\Cao Kangkang\AppData\Roaming\Python\Python36\site-packages\pygal\_compat.py", line 62, in to_unicode
return string.decode('utf-8')
AttributeError: 'NoneType' object has no attribute 'decode'

*无论如何,如果我将部分代码更改为此,错误将消失,*但是图表中的描述将被忽略。
names, plot_dicts = [], []
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['owner']['html_url'],
}
plot_dicts.append(plot_dict)

*我不知道为什么,谁能帮我解决这个问题?

最佳答案

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

像上面一样尝试 str() ,看来您之前获得的数据还没有阐明“描述”存储的值的类型。

关于python-3.x - 属性错误 : 'NoneType' object has no attribute 'decode' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44004609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com