Flask——Http request

Flask--HTTP request


In the process of deep learning model deployment and model application, we often save the detection results of the model in json files, databases or Redis, and we need to obtain the detection results of the model from Redis (database, json), and then perform corresponding post-processing. Process the analysis, then save the analyzed results in the corresponding location, and then push the video stream, image or video to the platform for display through the Flask request.
Here is a simple record of the relevant basis of the Flask request to ensure that you can understand the meaning during use.

request message

When a browser accesses a certain URL, it actually sends a request to the server where the domain name is located.
The essence of the request is some data sent to the server. The data exchanged between the browser and the server is called a message. The data sent by the browser during the request is called a request message. The data returned by the server is called a response message (response message).

The request message includes: request line, request header, and request body.
The request line contains: request method (get, post, etc.), URL, protocol version.
Common request methods: insert image description here
Among them, get is used to obtain resources, and it has no body. post is used to add or modify resources, and the sent content is written in the Body. (Here, I only use these two at present)
The request header contains some Token and cookies, etc.

Request object

Request encapsulates the request message sent from the client, and we can get all the data in the request message from it.
For example:

file = [('img', (img_name, open(imgPath, 'rb'), 'image/jpeg'))]
response = requests.request("POST", url, headers=headers, data=payload, files=files)
result = response.text.encode("utf8")
result = json.loads(result)

Generally, a POST request is sent through the request to submit our detection results. Our detection results are saved in the form of pictures and submitted to the platform for display.
Use result to check whether the submission is successful.

at last

Basically, a flask request is enough for my daily use, and the model's detection results are pushed to the platform through the request.

Guess you like

Origin blog.csdn.net/renxingshen2022/article/details/130347166