O
O
Ozrae2020-02-10 14:52:37
Flask
Ozrae, 2020-02-10 14:52:37

I can't understand: how do post requests work in python?

There is a flask server that when going to the address " 127.0.0.1:5000/get " gives an empty page with a single dictionary: {"foo": "var"}. With a get request, everything was quite simple and clear, but uploading your dictionary to the page does not work with a post request. It gives me a 405 error
. How can I write a post request so that another dictionary is displayed on the page? How to change an existing dictionary?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pankov, 2020-02-10
@trapwalker

Read how the HTTP protocol works at least on the wiki .
There is an http server that waits for connections on its port and processes requests.
Each request is characterized by a method (get, post, put, head, etc.), an address (and this is a separate factor that has nothing to do with the method), headers (there we have the client's wishes about the response format, all sorts of cookies, info about client), body (there we have post-request form data, just uploaded files like an avatar or json...).
Each such request is received by the server and gives some kind of response to it, or can even be ignored by closing or not closing the connection.
To write a post request is, as it should be understood, to write code to perform a post request (from the client to the server, of course, it doesn’t happen otherwise).
If the server at this address or for some other reason does not accept a post request, then you cannot force it to do so from the client side.
Even if you beat with a stick.
The server will answer you with an error with some code. If the server developers are great, then the error code will be relevant to the situation, but in general there can be anything nt[ybxtcrb, even 666 Devil request success.
You didn't show the source code of the server here, you didn't show an example of the code you are using, you don't understand even closely how the HTTP protocol works, you don't understand what you're asking...
How do you even expect to understand what you're being answered?
Facepalm.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question