import pygal
import requests
from pygal.style import LightColorizedStyle as LCS, LightenStyle as LS
url='https://api.github.com/search/repositories?q=language:python&sort=stars'
r = requests.get(url)
print('States code:', r.status_code)
# 将API响应存起来
response_dict = r.json()
print("Total repositories:", response_dict['total_count'])
#
repo_dicts = response_dict["items"]
# print(response_dict.keys())
print("Repositories returned:", len(repo_dicts))
'''
repo_dict = repo_dicts[0]
print("\nKeys:", len(repo_dict))
for key in sorted(repo_dict.keys()):
print(key)
'''
print("\nSelected information about first repository:")
names, stars = [], []
plot_dicts = []
for repo_dict in repo_dicts:
print("\nName:", repo_dict['name'])
names.append(repo_dict['name'])
print("Owner:", repo_dict['owner'])
print(&
《python从入门到实践》第17章 -使用pygal可视化仓库,'NoneType' object has no attribute 'decode' 问题
最新推荐文章于 2022-10-11 00:11:51 发布
在《python从入门到实践》第17章中,遇到使用pygal进行数据可视化时遇到'NoneType' object has no attribute 'decode'的问题。原因是某些仓库的描述为空值。解决方案是在添加描述到字典前,先确保将描述转换为str类型,从而避免空值错误。参考了Zhihu上的相关问题解答成功解决问题。
摘要由CSDN通过智能技术生成