python接口测试入门

我是使用虫师大大写的接口练习的
接口练习工具: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', 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值