【问题标题】:How to fix "TypeError: __call__() takes 2 positional arguments but 3 were given" in tornado.wsgi?如何在 tornado.wsgi 中修复“TypeError:__call__() 需要 2 个位置参数但给出了 3 个”?
【发布时间】:2019-12-17 23:49:54
【问题描述】:

我正在尝试使用 wsgi 形式的龙卷风,因为服务器只接受 wsgi。

我已经为 tornado + wsgi 尝试了所有服务器变体,总是收到这个错误:__call__() takes 2 positional arguments but 3 were given

# app/__init__.py

import tornado.wsgi
import tornado.web
import wsgiref.simple_server


class MainHandler(tornado.web.RequestHandler):
    def get(self):
        self.render("templates/index.html")

def routes():
    return [
    (r"/", MainHandler),
]

class Application(tornado.wsgi.WSGIContainer):
    def __init__(self):
        handlers = routes()

        tornado.wsgi.WSGIContainer.__init__(self, handlers)

# wsgi.py 

import wsgiref.simple_server
from app import Application

application = Application()
server = wsgiref.simple_server.make_server('', 8888, Application())
server.serve_forever()

这是错误跟踪:

Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
TypeError: __call__() takes 2 positional arguments but 3 were given
127.0.0.1 - - [10/Aug/2019 17:40:58] "GET / HTTP/1.1" 500 59

我希望可以使用 tornado.wsgi,任何帮助都会很有用!

【问题讨论】:

    标签: tornado wsgi python-3.7


    【解决方案1】:

    WSGIContainer 则相反:它允许您在 Tornado 的 HTTP 服务器上运行 wsgi 应用程序,而不是在 WSGI 服务器上运行 Tornado 应用程序。

    在 Tornado 5.1 中,您可以使用 WSGIAdapter 执行此操作。在 Tornado 6.0 中,WSGIAdapter 消失了,不再有任何方法可以在 WSGI 服务器上运行 Tornado 应用程序;你必须使用 Tornado 的服务器。

    【讨论】:

    • py from app import make_tornado_app import tornado import tornado.wsgi import wsgiref.simple_server if __name__ == "__main__": # application = make_tornado_app() # http_server = tornado.httpserver.HTTPServer(application) # http_server.listen(8888) # tornado.ioloop.IOLoop.current().start() application = tornado.wsgi.WSGIContainer(make_tornado_app()) wsgi_app = tornado.wsgi.WSGIAdapter(application) server = wsgiref.simple_server.make_server('', 8888, wsgi_app) server.serve_forever() 还是一样的错误
    • 不要碰 WSGIContainer - 直接将你的 tornado 应用程序包装在 WSGIAdapter 中。
    猜你喜欢
    • 1970-01-01
    • 2019-12-12
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-27
    相关资源
    最近更新 更多