1

这是我得到的错误:“{'message': '处理此请求时发生未捕获的异常。您可以使用zappa tail命令调查此问题。', 'traceback': ['Traceback (last recent call last):\n' , ' File \"/var/task/handler.py\", 第 454 行,在处理程序中\n response = Response.from_app(self.wsgi_app, environ)\n', ' File \"/var/task/werkzeug/ wrappers.py\",第 903 行,在 from_app\n return cls(*_run_wsgi_app(app, environ, buffered))\n','文件\"/var/task/werkzeug/test.py\",第884行,在 run_wsgi_app\n app_rv = app(environ, start_response)\n', \"TypeError: 'NoneType' object is not callable\n\"]}"

我没有主块,因为 lambda 没有进入它。

我在 init.py 中有代码,我的类在另一个文件中。

有人可以帮忙吗?我一无所知,因为这是我第一次尝试 lambda 和 zappa。

这是我的 init.py:

from flask import Flask, jsonify, request
from flasgger import Swagger
from rulesEnginePy.RiskOfCancellation.RiskOfCancellation import 
RiskOfCancellation
from logging.handlers import RotatingFileHandler
import logging
from datetime import datetime

app = Flask(name)
Swagger(app, template={
'swagger': '2.0',
'info': {
'title': 'RRRE RofCXL API',
'description': 'API for RRRE (Right Revenue Rules Engine) RofCXL (Risk of 
Cancellation)',
},
'basepath': '/api',
})

log_handler = RotatingFileHandler(app.root_path + '/../logs/rrre.log', 
maxBytes=10000000, backupCount=10)
log_handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s | %(pathname)s:%(lineno)d | %
(funcName)s | %(levelname)s | %(message)s')
log_handler.setFormatter(formatter)
app.logger.addHandler(log_handler)

@app.route('/api//calculate/4', methods=['GET'])
def calculate4(name):
try:
app.logger.info('About to use service %s' % name)
sampleDate = datetime.strptime(request.args.get('date'), '%Y-%m-%d')
# for id, sample in samples.items():
WOM = calculators[name].week_of_month(sampleDate)
DOW = sampleDate.weekday()+1
riskOfCancellation = RiskOfCancellation.calculateRiskOfCancellationMOYDOW(int(sampleDate.month),int(DOW))
app.logger.info(
'Calculated Risk of Cancellation {0} for DOM {1}, DOW {2}, WOM {3} and MOY 
{4}'.format(
riskOfCancellation,
sampleDate.day,
DOW,
WOM,
sampleDate.month
)
)
calculations = {
'DOM': sampleDate.day,
'DOW': DOW,
'WOM': WOM,
'MOY': sampleDate.month,
'riskOfCancellation': riskOfCancellation
}
app.logger.info('Done making calculations for request for calculate 4')
return jsonify({
'data': calculations,
})
except KeyError:
return jsonify({
'errors': [{
'code': '1000',
'title': 'A service with the given name doesn't exist',
}],
}), 404

仅供参考 - 上面的代码在本地机器(Vagrant、venv、Python 3.6、Flask)上运行良好。

感谢你的帮助

4

0 回答 0