当前位置:网站首页>Interface test framework practice (I) | requests and interface request construction
Interface test framework practice (I) | requests and interface request construction
2022-06-27 00:40:00 【Hua Weiyun】

Requests Is an elegant and simple Python HTTP library , Actually Python Built in resource module for accessing the network , such as urllib, But it's not as good as Requests Simple and elegant , And it lacks many practical functions . therefore , More recommended to master Requests Interface test practical skills , This is also a popular interface testing tool for Internet manufacturers .
The following is the installation Requests Library starts , Master the interface request structure step by step 、 Interface request assertion 、Schema Assertion 、Json/XML request 、 Test case debugging 、HeadCookie Handle 、Jsonpath application 、 Certification system and other interface testing skills .
pip Command to install Requests.
Requests Official documents :
https://2.python-requests.org/en/master/
Then we'll use the most popular Requests Conduct interface test .
Requests Provides almost everything HTTP Request construction method , And the method of passing in parameters , Customize the configuration of the sent request , It can be used to deal with various request scenarios .
send out get request :
Add... To the request data Parameters , And send the post request :
Add... To the request data Parameters , And send the put request :
send out delete request :
send out head request :
send out options request :
It can also be used directly request function , Introduce different method, For example, use this method to send get request :
The following parameters are not required , But if additional customization of the request is needed , You need to master the functions of the following parameters .
header Parameters
By passing in dict Custom request header :data Parameters
Send a data sheet encoded as a form :files Parameters
Upload files ,dict Format .
Be careful : Binary mode is recommended (binary mode) Open file . This is because Requests May try to provide you with Content-Length header, When it does so , This value will be set to the number of bytes in the file (bytes). If you use text mode (text mode) Open file , There could be mistakes .timeout Parameters
Set the timeout ( second ), When this time is reached, it will stop waiting for a response :
Be careful :timeout Only valid for connection process , Nothing to do with the download of the response body .timeout It's not the entire download response time limit , But if the server is timeout No response in seconds , An exception will be thrown ( To be more precise , Is in timeout When no bytes of data are received from the underlying socket within seconds ), If not set timeout, Will be waiting for .allow_redirects Parameters
Controls whether redirection is enabled ,bool type , choice True To enable , choice False To disable .proxies Parameters
Setting agent ,dict Format ,key The value is the selected protocol , It can be set separately HTTP Request and HTTPS The requested agent .verify Parameters
You can pass in bool Value or string, The default is True. If set to False To ignore is to ignore SSL Certificate verification ; On the contrary, verification is needed ; If the pass in value is string Words , Specifies the local certificate as the client certificate .
Pass in the certificate locally :
Ignore right SSL Certificate verification :
Three other important parameters Json、Cookies、Auth It will be introduced in detail in the following chapters .
边栏推荐
- 滑环选型选购时需要注意的技巧
- “message“:“Bad capabilities. Specify either app or appTopLevelWindow to create a session“
- 简单快速的数网络(网络中的网络套娃)
- [microservice]eureka
- 为什么EDR需要深度防御来打击勒索软件?
- 2022 Health Expo, Shandong health care exhibition, postpartum health and sleep health exhibition
- Encapsulate servlet unified processing request
- 指南针开户安全的吗?
- Pet hospital management system based on SSMP
- When transformer encounters partial differential equation solution
猜你喜欢
![[microservices] understanding microservices](/img/62/e826e692e7fd6e6e8dab2baa4dd170.png)
[microservices] understanding microservices

Lambda表达式

No clue about complex data?
![[vscade] preview MD file](/img/b8/0413eaade0a7da9ddb5494b093665c.png)
[vscade] preview MD file

CPU exception handling

目标追踪拍摄?目标遮挡拍摄?拥有19亿安装量的花瓣app,究竟有什么别出心裁的功能如此吸引用户?

com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x

Sword finger offer 10- ii Frog jumping on steps
![[vscode] setting sync, a plug-in for synchronizing extensions and settings](/img/e0/4889b59105e9815d11ae31988f58f2.jpg)
[vscode] setting sync, a plug-in for synchronizing extensions and settings

Amway! How to provide high-quality issue? That's what Xueba wrote!
随机推荐
论文解读(LG2AR)《Learning Graph Augmentations to Learn Graph Representations》
CPU exception handling
超硬核!华为智慧屏上的家庭相册竟可以自动精准分类?
test
Special topic II on mathematical physics of the sprint strong foundation program
手机炒股靠谱吗 网上开户炒股安全吗
MATLAB data type - character type
“message“:“Bad capabilities. Specify either app or appTopLevelWindow to create a session“
05 | standard design (Part 2): how to standardize the different styles of commit information, which are difficult to read?
Installation of xshell and xftp
[microservice]eureka
find_circ详细使用指南
安利!如何提优质的ISSUE?学霸是这样写的!
com.fasterxml.jackson.databind.exc.MismatchedInputException: Expected array or string. at [Source:x
Is there anyone who doesn't know the three cores of concurrent programming?
国内外最好的12款项目管理系统优劣势分析
基于SSMP的宠物医院管理系统
根据文件名批量生成文件夹
Nacos安装指南
我的c语言进阶学习笔记 ----- 关键字