NoneType object has no attribute 'decode'该怎么解决??

折射线 2017-09-16 09:32:48
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import requests
import pygal
from pygal.style import LightColorizedStyle as LCS,LightenStyle as LS

#执行API调用并存储响应
url='https://api.github.com/search/repositories?q=language:python&sort=stars'
r=requests.get(url)
print 'Status code:',r.status_code #打印status_code
response_dict=r.json()
print 'Total repositories:',response_dict['total_count']

#研究有关仓库的信息
repo_dicts=response_dict['items']
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'],'http_address':repo_dict['html_url']}
plot_dicts.append(plot_dict)



#可视化
my_style=LS('#333366',base_style=LCS)
my_config=pygal.Config()
my_config.x_label_rotation=45
my_config.show_legend = False
my_config.title_font_size=24
my_config.label_font_size=14
my_config.truncate_label=15
my_config.show_y_guides=True
my_config.width=1000

chart=pygal.Bar(my_config,style=my_style) #创建图表
chart.title='Most-Starred Python Project on GitHub'
chart.x_labels=names

chart.add('',plot_dicts)
chart.render_to_file('python_repos.svg')
...全文
2474 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
robator 2019-09-22
  • 打赏
  • 举报
回复 3
'label':repo_dict['description']改为: 'label':str(repo_dict['description'])
nanxujuan 2017-12-19
  • 打赏
  • 举报
回复 30
'NoneType' object has no attribute 'decode' 这个报错信息提示有一个变量的值是None None 的类型是NoneType , 它没有decode 方法。 把repo_dict['description']转为str形式就好了 https://www.zhihu.com/question/65438974
dsagsdfs 2017-09-24
  • 打赏
  • 举报
回复
同样的问题,后来发现是python_repos.svg文件过大造成的,截取一部分就好了

37,744

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • WuKongSecurity@BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧