[英]TypeError: __call__() takes 2 positional arguments but 3 were given
[英]WSGIServer TypeError: __call__() takes 3 positional arguments but 4 were given
我正在使用Flask和Python 3.7。 我已經實現了一個hello world應用程序,如下所示:
from wsgiref.simple_server import WSGIServer
from flask import request, json
from base.flask_instance import FlaskInstance
app = FlaskInstance.get_instance()
@app.route('/hello', methods=['GET'])
def _signup():
try:
return "hello world"
except BaseException as e:
print(e)
if __name__ == '__main__':
# for using in development server.
app.run(debug=True, host='0.0.0.0', port=5000)
# for using in production server.
http_server = WSGIServer(server_address=('', 5000), RequestHandlerClass=app)
http_server.serve_forever()
當我使用此代碼段運行它時,它工作正常:
app.run(debug=True, host='0.0.0.0', port=5000)
但是,此代碼段適用於開發服務器,不應在生產部署中使用。 因此,我正在使用此代碼段運行應用程序:
http_server = WSGIServer(server_address=('', 5000), RequestHandlerClass=app)
http_server.serve_forever()
此代碼段也運行良好,但是在調用post請求后,它將引發以下異常:
Exception happened during processing of request from ('192.168.1.13', 1978)
Traceback (most recent call last):
File "C:\Users\milad\AppData\Local\Programs\Python\Python37\lib\socketserver.py", line 316, in _handle_request_noblock
self.process_request(request, client_address)
File "C:\Users\milad\AppData\Local\Programs\Python\Python37\lib\socketserver.py", line 347, in process_request
self.finish_request(request, client_address)
File "C:\Users\milad\AppData\Local\Programs\Python\Python37\lib\socketserver.py", line 360, in finish_request
self.RequestHandlerClass(request, client_address, self)
TypeError: __call__() takes 3 positional arguments but 4 were given
如果我通過Python 2.7運行此應用程序,它將像一個魅力一樣運行! 我應該怎么做才能用Python 3.7運行它?
# from wsgiref.simple_server import WSGIServer
from gevent.pywsgi import WSGIServer
from flask import request, json, Flask
# from base.flask_instance import FlaskInstance
#
# app = FlaskInstance.get_instance()
app = Flask(__name__)
@app.route('/hello', methods=['GET'])
def _signup():
try:
return "hello world"
except BaseException as e:
print(e)
if __name__ == '__main__':
# for using in development server.
# app.run(debug=True, host='0.0.0.0', port=5000)
# for using in production server.
http_server = WSGIServer(('', 5000), app)
http_server.serve_forever()
您應該從“ gevent.pywsgi”導入“ WSGIServer”,並且WSGIServer()的輸入類型已更改
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.