菁英科技(卓目鸟学苑)- 专注软件测试菁英教育
标题:
自动化接口-homework
[打印本页]
作者:
5269
时间:
2021-3-18 20:01
标题:
自动化接口-homework
'''
timeout
参数,设置请求的超时时间
1
。接口执行耗时比较久,磨人的超时时间内执行不完,比如上传一个
2G
的大文件
2.
接口性能要求,接口在
xx ms
内返回结果。超过
xx ms
,认为性能不符合要求
'''
import
requests
#
淘宝查询手机号码归属地接口
# tcc.taobao.com/cc/json/mobile_tel_segment.htm
接口地址
url =
"https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=18012345678"
#
该接口是否能在
200ms
返回结果
for
i
in
range
(
10
):
try
:
r = requests.get(url
,
timeout
=
0.5
)
# timeout=0.2 Connection to tcc.taobao.com timed out.
时间太短了
# print(r.text)
print
(r.status_code)
except
Exception
as
e:
print
(e)
'''
设置代理抓包
1.
界面执行是正确的
2.
接口执行时有问题
分别抓取界面执行过程的包,以及脚本执行过程的包,对比差异来定位问题
'''
proxy = {
"http"
:
"http://127.0.0.1:8888"
,
#
协议:代理地址
"https"
:
"http://127.0.0.1:8888"
}
r = requests.get(
"http://wwwbaidu.com"
,
proxies
=proxy)
print
(r.status_code)
#
证书校验失败:
certificate verify failed,
设置
verify=False
不去校验证书
#
执行时会出现警告,
InsecureRequestWarning
不影响执行
r = requests.get(
"https://www.bagevent.com"
,
proxies
=proxy
,
verify
=
False
)
print
(r.status_code)
欢迎光临 菁英科技(卓目鸟学苑)- 专注软件测试菁英教育 (http://www.zmnxy.com/)
Powered by Discuz! X3.4