我正在尝试运行一个简单的服务器
from klein import Klein
app = Klein()
@app.route("/")
def hello(request):
return "Hello World!"
if __name__ == "__main__":
run("localhost", 8080)
我使用Zappa打包并将其上传到AWS Lambda,悬停在调用端点后得到此消息,知道为什么吗?
"{'message': 'An uncaught exception happened while servicing this request. You can investigate this with the `zappa tail` command.', 'traceback': ['Traceback (most recent call last):\\n', ' File \"/var/task/handler.py\", line 452, in handler\\n response = Response.from_app(self.wsgi_app, environ)\\n', ' File \"/var/task/werkzeug/wrappers.py\", line 939, in from_app\\n return cls(*_run_wsgi_app(app, environ, buffered))\\n', ' File \"/var/task/werkzeug/test.py\", line 923, in run_wsgi_app\\n app_rv = app(environ, start_response)\\n', ' File \"/var/task/zappa/middleware.py\", line 70, in __call__\\n response = self.application(environ, encode_response)\\n', \"TypeError: 'Klein' object is not callable\\n\"]}"
答案 0 :(得分:0)
它不能调用对象 Klein()。您需要将其添加到virtualenv中,以便将其导入,因为只有virtualenv是使用zappa构建和部署的。
例如,您可以创建一个setup.py脚本,该脚本允许通过pip将自定义代码安装到您的虚拟环境中,如下所述:https://docs.python.org/3/distutils/setupscript.html