python-requests接口自动化测试

一.概念

requests是一个很实用的Python HTTP客户端库,编写爬虫和测试服务器响应数据时经常会用到,Requests是Python语言的第三方的库,专门用于发送HTTP请求

二.前提

要在pycharm的黑窗口中下载requests

pip install requests

在这里插入图片描述

三.get请求

// get请求案例:
    get第一种方式.url和参数都放在一起
   url="http://apis.juhe.cn/mobile/get?phone=17319306584&dtype=&key=02e47c6e71e9445573d1a533748152aa"
   response=requests.get(url)
   print(response.text)

    get第二种方式,url和参数分开
   url="http://apis.juhe.cn/mobile/get"
   phontparams={"phone":"17319306584","key":"02e47c6e71e9445573d1a533748152aa"}
   response=requests.get(url,params=phontparams)
   print(response.text)

四.post请求

// post请求案例:
  url = "http://web.juhe.cn:8080/constellation/getAll"
  phontparams = {"consName": "金牛座","type":"today", "key": "2665ea77f94444275a571b04483e0f31"}
  response = requests.post(url, data=phontparams)
  print(response.text)

五.requests的响应内容

// requests的响应内容
r.status_code        响应状态码
r.heards             响应头
r.cookies            响应cookies
r.text               响应文本
r. encoding          当前编码
r. content		    以字节形式(二进制)返回

六.requests的扩充

1:添加等待时间
requests.get(url,timeout=1) #超过等待时间则报错
2:添加请求头信息
requests.get(url,headers=headers) #设置请求头
3:添加文件
requests.post(url, files=files) #添加文件

七.requests+pytest+allure

链接: python-requests+pytest+allure实现读取csv文件及excel文件

( ̄▽ ̄)~*------ ٩(๑❛ᴗ❛๑)۶谢谢阅读!!!!!!!!!!!!!!!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值