Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Detailed explanation of the basic usage of requests Module in Python Module

Shulou Source: shulou.com Published: 2022-06-01 04:22:59 10月06日 Update

First of all, let's talk about the definition and function. Request module is a module used to access the network. In fact, there are many similar modules, which will not be explained here one by one. Why do so many similar modules say that this is the only good one? Because he's humanized. If you have learned modules such as urllib, it will be clear to compare them (the article url is quick to experiment with the title).

1. No matter what kind of script we write, we know that we need to import the module we need first.

2. Since this module is a module for accessing the network, let's pass him a url and send a get request.

Because we are working on the ctf topic, take the url of the title as an example.

After sending it, we will get the corresponding object re, which contains the corresponding information we want. Here, if nothing is done to process the output, the status code of the request will be returned. If you want the content to appear, you need to add .text. Output in string format. In the same way, post delivery is the same.

3. Request for parameters of the transmitting belt

Get request: when sending a get request, its parameter is passed by the keyword params. Let's test it.

Post request: when sending a post request, it is passed with data as the keyword parameter. Test it.

4. Get a field in the response header

We can use headers to test this.

Get all fields

To get the specified field, such as this topic, I want to get the FLAG field

What re.headers' gets is a dictionary, and if we want to get one, we can get it in this form.

If we want to get the request header, we can directly re.request.headers and test it.

5. At the end of the article, send the python script of the ctf topic, the topic is that the experiment bar is quick but not broken.

Code

Tags: Module title field test parameter key keyword article network script unbroken experiment output clear similar code function information content only Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MySQL OPPO Reno NVidia Docker