TypeError: takes no arguments (2 given) when using

2019-09-10 05:42发布

I am using mod-wsgi with Apache 2.2

I have the following in WSGI script

import sys
sys.path.insert(0, '<path to my app>')

from optimization_app import optimizeInstances as application

and optimization_app.py as follows:

from flask import Flask
from flask_restful import Api
from resources.Optimization import OptimizationAlgo

def optimizeInstances():
    optimization_app = Flask(__name__)
    api = Api(optimization_app)
    api.add_resource(OptimizationAlgo, '/instances')

When I try to access the app url, I get the following in my apache error_log

TypeError: optimizeInstances() takes no arguments (2 given)

2条回答
混吃等死
2楼-- · 2019-09-10 06:09

As I see u defined optimizeInstances() with No arguments. You might be calling optimizeInstances() function by passing 2 arguments to it.

查看更多
手持菜刀,她持情操
3楼-- · 2019-09-10 06:32

This is occurring because you used it as the WSGI application object.

from optimization_app import optimizeInstances as application

A WSGI application is required to accept two parameters environ and start_response. So when the WSGI server is calling that function to have your application handle a request it is failing with that error.

The way you are using that function is simply wrong. Your actual WSGI application is being created inside of that function in local scope, so how would it be accessed anyway.

Would suggest you check back and look at the Flask getting started documentation.

查看更多
登录 后发表回答