There is a script on the hosting

@app.route('/', methods=['POST']) def processing(): #Распаковываем json из пришедшего POST-запроса data = json.loads(request.data) #Вконтакте в своих запросах всегда отправляет поле типа if 'type' not in data.keys(): return 'not vk' if data['type'] == 'confirmation': return confirmation_token elif data['type'] == 'message_new': session = vk.Session(access_token=token_group) api = vk.API(session) ## Делаем что угодно return 'ok' 

So, vk duplicates requests, although the solution to the problem is to return 'ok', which I do only it does not solve the problem. What could be the snag?

    3 answers 3

    In the admin panel in the Callback API settings, check the request history. All successful requests are described there, all unsuccessful too (and you can see what the server returned).

    Requests are repeated only if the answer did not meet the requirements (body ok and code 200). The problem is on your side, just check.

    • On the VK side, he sees them as sent! But the logs from the server are uwsgi_response_writev_headers_and_body_do (): Broken pipe [core / writer.c line 296] during POST --- --- SIGPIPE: writing to a closed pipe / socket / fd (probably the client disconnected) on request --- The essence of what the script works for me about 10 seconds, I understand the error is that VK closes the connection or something like that, how to solve it, I xs - Xstyle71
    • @ Xstyle71 they have a timeout of about 20 seconds, like. It should be enough for you. I usually in such cases immediately return the answer, and then start a long work. You can asynchronously start the execution of tasks, and immediately return the answer VK. - Peter Samokhin
    • No, the point is that after 10 seconds I return the answer to the user who wrote the bot message! If the script is returned immediately, the script is interrupted. My script of the type is received, it generates some errors, although they are not in pycharm, and not only ok is returned to vk. - Xstyle71
    • I now made a test asked to return ok after a banal answer! Resons 1 second, 20 minutes VC re-sent a request to the server, although I did not write a message to the bot. - Xstyle71
    • @ Xstyle71 check in the admin panel whether the VC considers your request correct, and if not, why not. - Peter Samokhin

    Problem solved!

    1. You need to make an SSL certificate for Flask you can import a library: from flask_sslify import SSLify app = Flask ( name ) sslify = SSLify (app)
    2. The script worked for more than 8 seconds, in VK they said that it was necessary to give a response within 10 seconds. I solved the problem by optimizing the script and putting it in this time range!

      VC duplicates messages because your code does not send in response to the Callback "ok" due to received errors in the code

      This is inevitable in code development, so I advise you to add an error handler.

      You can add such code to the end.

       @app.errorhandler(500) def handler(e): # уведомляете админа об ошибке # ... # возвращаете ВК ok return 'ok' 

      Then VC, even with errors, will send Callback only once