Interface Test - Introduction to Requests Library

1. Requests library

The Requests library is written in Python language, based on the urllib3 module, and uses the HTTP library of the Apache2 Licensed open source protocol.

Although the urllib3 module in Python's standard library already contains most of the functions we usually use, its API feels unfriendly to use. The Requests library uses urllib3, so it inherits all its features, so the Requests library is more convenient to use than urllib3, which can save us a lot of work and fully meet the HTTP testing requirements.

The Requests library supports HTTP connection retention and connection pooling, supports session retention using cookies, supports file uploads, supports automatic determination of the encoding of response content, and supports automatic encoding of internationalized URL and POST data. Modern, international and humanized.

The Requests library calls itself "HTTP for Humans" (let HTTP serve humans), which means that it is more concise and convenient to use.

The Requests library is developed around the maxims of PEP 20

  1. Beautiful is better than ugly. (Beautiful is better than ugly)
  1. Explicit is better than implicit. (straightforward is better than implicit)
  1. Simple is better than complex. (Simple is better than complex)
  1. Complex is better than complicated. (complex is better than complicated)
  1. Readability counts. (readability is very important)

All contributions to Requests should keep these important guidelines in mind.

In short: the Requests library is equivalent to the "browser" in Python, through which you can make network requests and obtain web page data. It is powerful and easy to use.

Description of PEP20 :

pythonPEP20 is the guideline for writing programs. You can see the guidelines for writing programs by python shelltyping in . The content is as follows:import thispythonpython shellimport this

TIM Peters的python之禅
The Zen of Python, by Tim Peters


优美胜于丑陋。
Beautiful is better than ugly.

明确胜于隐晦。
Explicit is better than implicit.

简单胜于复杂。
Simple is better than complex.

复杂胜于难懂。
Complex is better than complicated.

扁平胜于嵌套。
Flat is better than nested.

留白胜于紧凑。
Sparse is better than dense.

可读性很重要。
Readability counts.

特例也并不能特殊到可以违背这些原则。
Special cases aren't special enough to break the rules.

虽然实用性胜于纯粹性。
Although practicality beats purity.

错误不应被默默地忽略。
Errors should never pass silently.

除非你明确地忽视。
Unless explicitly silenced.

面对歧义,不要尝试去猜测。
In the face of ambiguity, refuse the temptation to guess.

应该有一种,最好是仅有一种,明显的处理方式。
There should be one-- and preferably only one --obvious way to do it.

一开始那种方式并非显而易见,除非你是python之父。
Although that way may not be obvious at first unless you're Dutch.

做好过不做。
Now is better than never.

不假思索就动手还不如不做。
Although never is often better than *right* now.

如果实现很难解释,那就不是个好思路。
If the implementation is hard to explain, it's a bad idea.

如果实现易于解释,则可能是个好思路。
If the implementation is easy to explain, it may be a good idea.

命名空间是个绝妙的主意,我们要多多利用它。
Namespaces are one honking great idea -- let's do more of those!

2. Requests library documentation

3. Requests library installation

python -m pip install requests(推荐)The prerequisite for installing the Requests library is to install the python environment, and then enter or on the cmd command line pip install requests.

As shown below:

Execute pip listto check whether the Requests library is successfully installed, and the installed version (the highest version is installed by default.)

C:Users\ailin-L>pip list 
Package     Version 
-------     --------
certifi     2020.12.5
chardet     4.0.0
idna        2.10
pip         19.2.3
requests    2.25.1
selenium    3.141.0
setuptools  41.2.0
ur11ib3     1.25.9

END meager strength

Finally, I would like to thank everyone who has read my article carefully. Looking at the fans’ growth and attention all the way, there is always a need for reciprocity. Although it is not a very valuable thing, you can take it away if you need it:

These materials should be the most comprehensive and complete preparation warehouse for [software testing] friends. This warehouse has also accompanied tens of thousands of test engineers through the most difficult journey, and I hope it can help you too!

加入我的软件测试交流群:110685036免费获取~(同行大佬一起学术交流,每晚都有大佬直播分享技术知识点)

Software testing interview applet

The software test question bank maxed out by millions of people! ! ! Who is who knows! ! ! The most comprehensive quiz mini program on the whole network, you can use your mobile phone to do the quizzes, on the subway or on the bus, roll it up!

The following interview question sections are covered:

1. Basic theory of software testing, 2. web, app, interface function testing, 3. network, 4. database, 5. linux

6. web, app, interface automation, 7. performance testing, 8. programming basics, 9. hr interview questions, 10. open test questions, 11. security testing, 12. computer basics

method of obtaining:

 
 

Guess you like

Origin blog.csdn.net/jiangjunsss/article/details/130620779