王亿亿 2020-07-14 17:03 采纳率: 0%
浏览 252

Pygal条形图表报错AttributeError: 'NoneType' object has no attribute 'decode'

import requests
import pygal
from pygal.style import LightColorizedStyle as LCS # 类
from pygal.style import LightenStyle as LS # 类
from requests.packages import urllib3
urllib3.disable_warnings() # 关闭warning

# 执行API调用
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
r = requests.get(url, verify=False) # 返回JSON格式信息
print("Status code:", r.status_code) # 属性表示是否请求成功,200表示成功。200

# 存储API响应
response_dict = r.json() # 把JSON转换为一个Python字典
print("Total repositories:", response_dict['total_count']) # 5577125

# 仓库
repo_dicts = response_dict['items'] # 每个元素都是一个字典
# 存储名字,获得的星星
names, stars, plot_dicts = [], [], []
for repo_dict in repo_dicts:
    names.append(repo_dict['name'])
    stars.append(repo_dict['stargazers_count'])
    plot_dict = {
        'value': repo_dict['stargazers_count'],
        'label': repo_dict['description'],
        'xlink': 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 # x轴标签旋转45度
my_config.show_legend = False # 隐藏图例
my_config.title_font_size = 24
my_config.label_font_size = 14
my_config.major_label_font_size = 18
my_config.truncate_label = 15 # 名称限制15个字符,移动光标可显示完整
my_config.show_y_guides = False # 隐藏水平线
my_config.width = 1000

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

# chart.add('', plot_dicts)
chart.add('', stars)
chart.render_to_file('python_repos.svg')

使用chart.add('', plot_dicts)作图会报错,但是用chart.add('', stars)不会,是因为这个列表哪里搞错了吗

  • 写回答

1条回答 默认 最新

  • threenewbee 2020-08-01 16:44
    关注

    print(plot_dicts)
    看看,是不是none了

    评论

报告相同问题?

悬赏问题

  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行