本文介绍了TypeError:在Python 2.7中使用WSGI时不接受任何参数(给定2个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Apache 2.2上使用mod-wsgi

I am using mod-wsgi with Apache 2.2

我在WSGI脚本中有以下内容

I have the following in WSGI script

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

from optimization_app import optimizeInstances as application

optimization_app.py如下:

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')

当我尝试访问应用程序URL时,我在Apache error_log中得到以下内容

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

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

推荐答案

之所以发生这种情况,是因为您将其用作WSGI application对象.

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

from optimization_app import optimizeInstances as application

要求WSGI应用程序接受两个参数environstart_response.因此,当WSGI服务器调用该函数以使您的应用程序处理请求时,它会因该错误而失败.

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.

您使用该功能的方式是完全错误的.您的实际WSGI应用程序是在本地范围内的该函数内部创建的,因此无论如何将如何对其进行访问.

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.

建议您回来查看一下Flask入门文档.

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

这篇关于TypeError:在Python 2.7中使用WSGI时不接受任何参数(给定2个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 20:55