python 服务器响应时间过长,python接口自动化20-requests获取响应时间(elapsed)与超时(timeout) ok试了 获取响应时间的...

前言

requests发请求时,接口的响应时间,也是我们需要关注的一个点,如果响应时间太长,也是不合理的。

如果服务端没及时响应,也不能一直等着,可以设置一个timeout超时的时间

关于requests请求的响应时间,官网上没太多介绍,并且我百度搜了下,看很多资料写的是r.elapsed.microseconds获取的,然而都是错的!!!

elapsed官方文档

requests.Response

elapsed = None

The amount of time elapsed between sending the request and the arrival of the response (as a timedelta). This property specifically measures the time taken between sending the first byte of the request and finishing parsing the headers. It is therefore unaffected by consuming the response content or the value of the stream keyword argument.

简单翻译:计算的是从发送请求到服务端响应回来这段时间(也就是时间差),发送第一个数据到收到最后一个数据之间,这个时长不受响应的内容影响

2.用help()查看elapsed里面的方法

import requests

r = requests.get("https://www.baidu.com")

help(r.elapsed)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值