【发布时间】:2020-06-18 05:50:00
【问题描述】:
如果请求成功,我有一个可以正常工作的端点,否则会使代码崩溃(不是预期的行为)
class CarbyID(Resource):
def get(self, car_id):
json_return = {'car_id': car_id}
try:
res = db_query.read(car_id) #gets the data from the databse
json_return['data'] = res
return json_return, 200 if res else json_return, 400
except:
return json_return,505
当在数据库中找到 car_id 时 --> OK.
当找不到 car_id 时, res 为 None 并期望返回 400,但返回 500 并出现以下错误:
File "\Lib\site-packages\werkzeug\datastructures.py", line 1091, in extend
for key, value in iterable:
ValueError: too many values to unpack (expected 2)
知道为什么吗?是同一个结构的json+状态码。
【问题讨论】: