为什么我的 Lambda API via Chalice 给出内部服务器错误而不是日期时间值?

Why is my Lambda API via Chalice giving an internal server error instead of a datetime value?

/date 的 API 结果给出了 {"message": "Internal server error"} 错误。 /hello 成功 returning 'hello world'.

最终目标是return今年到目前为止过去的天数。

'''

from chalice import Chalice
from datetime import date

app = Chalice(app_name='days')
app.debug = True

@app.route('/hello')
def index():
    return {'hello': 'world'}

@app.route('/date')
def days():
    return date.today()

'''

根据评论。

问题是 date.today() 没有 返回 json

解决方案是 将其转换为字符串 以便将其正确识别为 json 字符串:类似于 str(date.today())