G
G
George2018-09-06 16:37:56
Python
George, 2018-09-06 16:37:56

How to respond to POST requests in Python?

I tried to respond to POST requests from VKontakte servers, because I needed to confirm the server address for the callback api and create a bot. I still can't figure out how to implement it.
Task:
To receive notifications, you need to confirm the server address. A POST request containing JSON will be sent to it:
{ "type": "confirmation", "group_id": 1111111 }
The string that the server should return: ddddd

Answer the question

In order to leave comments, you need to log in

3 answer(s)
X
xoo, 2018-09-06
@hatepls

  1. Install falcon, gunicorn, nginx
  2. import falcon
    import json
    
    class CResourse(object):
    
      def on_post(self, req, res):
                  data = json.load(req.stream)
                  res.status = falcon.HTTP_200
                  res.body = 'ddd'
    
    app = falcon.API()
    app.add_route('/callback', CResourse())

  3. In the settings of the public, specify the address domain.com/callback

A
Alexander, 2018-09-06
@AlexNineteen

Flask:

from flask import Flask

app = Flask(__name__)

@app.route('/', methods=['POST'])
def response():
    return 'ddddd'

if __name__=='__main__':
    app.run()

S
Sergey Gornostaev, 2018-09-06
@sergey-gornostaev

According to the HTTP standard.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question