The origin of

As we all know, automated testing is a lifelong exploration of software testing enthusiasts. In my opinion, if you do interface testing well, your automated tests are at least half the battle.

At the request of some enthusiastic readers, Tester is here to take a look at python interface test library – Requests for basic usage and practice, hopefully to help you quickly get started with interface testing.

The body of the

What are Requests?

Simply put, Requests is a Python library that encapsulates HTTP/HTTPS Requests.

How do I install Requests?

Easier, PIP is better:

pip install requests
Copy the code

How do I use Requests?

Get request sample code

import requests

test = requests.get('http://www.baidu.com')

print(test)
Copy the code

Console output

<Response [200]>



Process finished with exit code 0
Copy the code

Congratulations, we successfully sent the first GET request to baidu home page. The return value of requests. Get is a Response object, and you can clearly see that the returned status code is 200.

Post request sample code

Let’s simulate a POST request with parameters this time.

The import requests test = requests. Post (url = 'http://47.106.10.19:5098/api/login', json = {' username ':' test ', 'the password: 'test'}).text print(test)Copy the code

Console output

{'''' omits '''' "status": "OK"} Process finished with exit code 0Copy the code

The requested address is the login interface of tester platform experience address. The requested parameters are JSON format data, including the correct account and password.

After taking the text attribute of the returned Response object, it can be clearly seen that status in the data returned by the interface is OK, indicating successful login.

conclusion

After this article, you’ll have a basic understanding of the Requests library, and we’ll see you next time.

Finally, I recommend my public account “intelligent test development”. You are welcome to scan the qr code below the poster to pay attention to the public account for advanced tutorial ~