实话实话直接看教程有点看不懂,先看博客写的api介绍
1.处理API响应
看了博客,再看教材会比较容易理解
import requests
url = 'https://api.github.com/search/repositories?q=language:python&sort=stars'
#accept用于指定客户端可接受哪些类型的信息数据的类型(vnd.github.v3+json是GitHub的官方定义 )
headers = {'Accept':'application/vnd.github.v3+json'}
r = requests.get(url,headers=headers)
print(f"Status code:{r.status_code}")
#将API响应赋值一个变量,json()转为字典
response_dict = r.json()
#处理结果
print(response_dict.keys())
标签:code,github,17,api,headers,json,API,相关
From: https://www.cnblogs.com/newblg/p/16919448.html