Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report