TypeError: takes no arguments (2 given) when using WSGI in Python 2.7

牧云@^-^@ 提交于 2019-12-25 06:26:20

问题


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)

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/36763304/typeerror-takes-no-arguments-2-given-when-using-wsgi-in-python-2-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!