Forums

Flask problem

Hi. I'm currently running simple vote bot for social media on pythonanywhere, and I'm facing very strange issue. After receiving message, something strange happen to Flask:

2019-11-23 21:00:28,807: Exception on / [POST]
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1816, in full_dispatch_request
    return self.finalize_request(rv)
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1831, in finalize_request
    response = self.make_response(rv)
  File "/usr/lib/python3.7/site-packages/flask/app.py", line 1957, in make_response
    'The view function did not return a valid response. The'
TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

and with the server: it starts to receive same message again and again and sometimes gives this:

2019-11-22 17:43:23 Fri Nov 22 17:43:23 2019 - SIGPIPE: writing to a closed pipe/socket/fd (probably the client disconnected) on request / (ip 10.0.0.249) !!!
2019-11-22 17:43:23 Fri Nov 22 17:43:23 2019 - uwsgi_response_writev_headers_and_body_do(): Broken pipe [core/writer.c line 306] during POST / (10.0.0.249)

My Flask app looks like this:

    from flask import Flask, request, json
    from settings import token, confirmation_token
    import messageHandler

    app = Flask(__name__)

    @app.route('/')
    def hello_world():
        return 'Hello from Flask!'

    @app.route('/', methods=['POST'])
    def processing():
        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':
            messageHandler.create_answer(data['object'], token)
            return 'ok'

    def curr_user_id():
        data = json.loads(request.data)
        user_id = data['object']['user_id']
        return user_id , 'ok'

Internet says that this Flask error is about returning None or function call in return, but there's nothing like this... What could be the root of the problem?

if none of the if / elif clauses are met, then it will return None.