0
非常簡單的問題,我嘗試了多種方法來解決,但我認爲我傳遞了一些非常容易解決的問題。如何通過API循環時遇到錯誤
import requests
# Make an API call and store the response.
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
r = requests.get(url)
print("Status code:", r.status_code)
# Store API response in a variable.
response_dict = r.json()
print("Total respositories:", response_dict['total_count'])
# Explore information about the respositories.
repo_dicts = response_dict['items']
print("Respositories returned:", len(repo_dicts))
print("\nSelected information about each respository:")
for repo_dict in repo_dicts:
print('\nName:', repo_dict['name'])
print('Owner:', repo_dict['owner']['login'])
print('Stars:', repo_dict['stargazers_count'])
print('Respository:', repo_dict['html_url'])
print('Description:', repo_dict['description'])
循環播放大多數加星項目的github api,並打印每個存儲庫的信息。其中一個存儲庫'沒有描述,所以我怎麼會跳過這個描述或說'沒有可用的描述',而沒有我的程序崩潰。
謝謝。