我是使用虫师大大写的接口练习的
接口练习工具:https://github.com/defnngj/learning-API-test
下载完后解压,在文件夹目录打开shell
安装依赖包:pip install -r requirements.txt
启动接口服务:python api_server.py
下面开始练习:
首先要import requests
接口测试例子
# r = requests.get('https://api.github.com/user',auth=('zhanzi123','zzy950714'))
#
# print(r.status_code)
# print(r.headers['Content-Type'])
# print(r.encoding)
# print(r.text)
# print(r.json())
先熟悉一下返回的结果构成
200
application/json; charset=utf-8
utf-8
{
"login":"zhanzi123","id":47934259,"node_id":"MDQ6VXNlcjQ3OTM0MjU5","avatar_url":"https://avatars2.githubusercontent.com/u/47934259?v=4","gravatar_id":"","url":"https://api.github.com/users/zhanzi123","html_url":"https://github.com/zhanzi123","followers_url":"https://api.github.com/users/zhanzi123/followers","following_url":"https://api.github.com/users/zhanzi123/following{/other_user}","gists_url":"https://api.github.com/users/zhanzi123/gists{/gist_id}","starred_url":"https://api.github.com/users/zhanzi123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zhanzi123/subscriptions","organizations_url":"https://api.github.com/users/zhanzi123/orgs","repos_url":"https://api.github.com/users/zhanzi123/repos","events_url":"https://api.github.com/users/zhanzi123/events{/privacy}","received_events_url":"https://api.github.com/users/zhanzi123/received_events","type":"User","site_admin":false,"name":null,"company":null,"blog":"","location":null,"email":null,"hireable":null,"bio":null,"public_repos":0,"public_gists":0,"followers":0,"following":0,"created_at":"2019-02-24T03:52:28Z","updated_at":"2019-10-14T12:25:40Z","private_gists":0,"total_private_repos":0,"owned_private_repos":0,"disk_usage":0,"collaborators":0,"two_factor_authentication":false,"plan":{
"name":"free","space":976562499,"collaborators":0,"private_repos":10000}}
{
'login': 'zhanzi123', 'id': 47934259, 'node_id': 'MDQ6VXNlcjQ3OTM0MjU5',