Q:

Python Flask: API call not happening, resulting in 500 internal server error

I am pretty new to Python Flask, setup a simple project using flask_restplus for making a basic API call. I am able to see my API in swagger page but that is resulting in 500 internal server error
run.py:
import os

from flask_script import Manager
from app.main import create_app

from app.app import blueprint

app = create_app(os.getenv('BOILERPLATE_ENV') or 'dev')
app.register_blueprint(blueprint)

app.app_context().push()

manager = Manager(app)

@manager.command
def run():
    app.run(threaded=True)

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

app.py:
from flask_restplus import Api
from flask import Blueprint
from .main.controller.hello_controller import api as hello

blueprint = Blueprint('api', __name__)

api = Api(blueprint,
          title='My RESTful API',
          version='1.0',
          description='My flask restplus web service'
          )

api.add_namespace(hello, path='/hello')

hello_controller.py:
import json
from flask import request
from flask_restful import Resource

api = Namespace('hello', description='hello world')

@api.route('/', methods=['GET'])
class Hello(Resource):
    @api.param('name1', 'Name1')
    @api.param('name2', 'Name2')
    @api.response(200, 'hello said successfully')
    @api.doc('Hello Names')
    def get(self, name1, name2):
        """ Get Hello names """
        return json.dump("Hello" + name1 + "and Hello" + name2), 200

Tried these two return types too, but no luck.
return json.dumps({'data': "Hello" + name1 + "and Hello" + name2, 'success': 200})

return Response(json.dumps("Hello" + name1 + "and Hello" + name2), mimetype='application/json')

When i try to execute the above API call from swagger UI, it's resulting in 500 Internal server error . In first place it's not even hitting my API route/method. This is the error from the console:
    ERROR:flask.app:Exception on /hello/ [GET]
Traceback (most recent call last):
  File "/Users/myuser/PycharmProjects/myDev/venv/lib/python3.6/site-packages/flask/app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/myuser/PycharmProjects/myDev/venv/lib/python3.6/site-packages/flask/app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/myuser/PycharmProjects/myDev/venv/lib/python3.6/site-packages/flask_restplus/api.py", line 325, in wrapper
    resp = resource(*args, **kwargs)
  File "/Users/myuser/PycharmProjects/myDev/venv/lib/python3.6/site-packages/flask/views.py", line 87, in view
    self = view.view_class(*class_args, **class_kwargs)
TypeError: object() takes no parameters
INFO:werkwal:127.0.0.1 - - [24/Jun/2019 21:43:27] "GET /hello/ HTTP/1.1" 500 -

If i try with this route: @api.route('/<name1>/<name2>', methods=['GET']) and execute from swagger its loading forever and nothing happens.Still the error is same:
    ERROR:flask.app:Exception on /hello/ [GET]
Traceback (most recent call last):
  File "/Users/myuser/PycharmProjects/myDev/venv/lib/python3.6/site-packages/flask/app.py", line 1832, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/myuser/PycharmProjects/myDev/venv/lib/python3.6/site-packages/flask/app.py", line 1818, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/myuser/PycharmProjects/myDev/venv/lib/python3.6/site-packages/flask_restplus/api.py", line 325, in wrapper
    resp = resource(*args, **kwargs)
  File "/Users/myuser/PycharmProjects/myDev/venv/lib/python3.6/site-packages/flask/views.py", line 87, in view
    self = view.view_class(*class_args, **class_kwargs)
TypeError: object() takes no parameters
    INFO:werkwla:127.0.0.1 - - [24/Jun/2019 21:19:29] "GET /hello/?name1=mike&name2=sam HTTP/1.1" 500 -

Any help is appreciated !

A:

Update: You import flask_restful not flask_restplus in hello_controller. There are a few errors with this example (I think from copying to SO). So it is hard to tell what is the real error or copying error. That's the best I can do without a clean example, sorry! See here for examples of using blueprints https://flask-restplus.readthedocs.io/en/stable/scaling.html#use-with-blueprints

