-1

I am quite new to python and I feel that what I want to do is not really complicated but I don't find the answer. I want to communicate between two scripts (running 24/24), I thought sending POST requests would be a great idea.

So I receive POST requests using flask with some content (characters as you can see in the example below). 172.31.128.1 - - [16/Jan/2023 21:58:47] "POST /?c51d94c2efccaa2092ad1028285549 HTTP/1.1" 405 -

I want to write the content in a txt file when I receive those requests. I know how to write in such files but I do not know how to get from receiving POST requests to saving content to variables (and so write them to files). Thank you very much !

davidism
  • 121,510
  • 29
  • 395
  • 339
Sean Ward
  • 1
  • 1

1 Answers1

0

when you get the post request in a specific route of your flask server you can using request get the data in the POST, like:

from flask import request
#...
@app.route('/post-something', methods=['POST'])
def hello():
    #the json in the post request
    some_json=request.get_json()

    #the data of the request
    data=request.data

    #save the data in a file
    #...

    return "Done!"

Mauxricio
  • 191
  • 9