前言

做接口自动化需要使用python发送请求,需要安装第三方模块requests实现发送get\post等请求

1.安装 requests

执行命令 pip install xx 是python的安装命令

python完成get请求 python get 请求_python

2.发送get请求

python完成get请求 python get 请求_python完成get请求_02

 

 默认返回的是状态码

如果需要查看内容 使用res.text属性

python完成get请求 python get 请求_get请求_03

 3.带有参数的get请求如何发送

带有参数的get请求需要传递params

python完成get请求 python get 请求_get请求_04

 

发送 get带有参数的接口需要使用params传递参数,可以看下get请求源码,必填参数url,默认参数params可以为None,后面关键字参数我们可以填写cookie、header等关键字参数

python完成get请求 python get 请求_python完成get请求_05