job_lists = response.json()["zpData"]["jobList"] KeyError: 'jobList'
时间: 2024-05-20 20:13:33 浏览: 10
这个错误很可能是因为在返回的 JSON 数据中没有名为 "jobList" 的键。可能是因为 API 的响应格式已经发生了变化,或者是因为你使用的参数不正确。你可以先检查一下 API 的文档或者和 API 提供方联系来确认 API 的响应格式是否有变化。另外,你还可以在代码中加入一些异常处理的逻辑,比如使用 try-except 块来捕获 KeyError 异常,并在出现异常时输出错误信息,以便更好地定位问题。
相关问题
修改以下代码,使他避开障碍物:def Astar(Map): s = Point(Map.start, None, None) openlist = [s] closedlist = [] s.get_f(Map.goal) while openlist: n = openlist.pop(0) if n.position[0] == Map.goal[0] and n.position[1] == Map.goal[1]: return n else: closedlist.append(n) subp_list = Point.EXPAND(n, Map) for subp in subp_list: subp.get_f(Map.goal) for openp in openlist: if openp.position[0] == subp.position[0] and openp.position[1] == subp.position[1]: if subp.f < openp.f: openlist.remove(openp) openlist.append(subp) for closedp in closedlist: if closedp.position[0] == subp.position[0] and closedp.position[1] == subp.position[1]: if subp.f < closedp.f: closedlist.remove(closedp) openlist.append(subp) openlist.append(subp) openlist.sort(key= lambda x:x.f)
Sure, here's the modified code that avoids obstacles using A* algorithm:
```
def Astar(Map):
s = Point(Map.start, None, None)
openlist = [s]
closedlist = []
s.get_f(Map.goal)
while openlist:
n = openlist.pop(0)
if n.position[0] == Map.goal[0] and n.position[1] == Map.goal[1]:
return n
else:
closedlist.append(n)
subp_list = Point.EXPAND(n, Map)
for subp in subp_list:
if Map.is_obstacle(subp.position[0], subp.position[1]):
continue
subp.get_f(Map.goal)
for openp in openlist:
if openp.position[0] == subp.position[0] and openp.position[1] == subp.position[1]:
if subp.f < openp.f:
openlist.remove(openp)
openlist.append(subp)
break
else:
for closedp in closedlist:
if closedp.position[0] == subp.position[0] and closedp.position[1] == subp.position[1]:
if subp.f < closedp.f:
closedlist.remove(closedp)
openlist.append(subp)
break
else:
openlist.append(subp)
openlist.sort(key=lambda x: x.f)
```
The modification is done by adding a check for obstacles in the sub-points list and skipping those points, as well as updating the open and closed lists based on the new condition.
from flask import Flask, render_template, request import pandas as pd from openpyxl import load_workbook app = Flask(__name__) @app.route('/') def index(): return render_template('index2.html') @app.route('/submit', methods=['POST']) def submit(): # 获取表单数据 line = request.form['line'] date = request.form['date'] model = request.form['model'] lists = request.form['lists'] number = request.form['number'] prod_date = request.form['prod_date'] shift = request.form['shift'] prod_line = request.form['prod_line'] responsible = request.form['responsible'] # 表单验证:检查是否所有表单字段都已填写 if not all([line, date, model, lists, number, prod_date, shift, prod_line, responsible]): return "<script>alert('请填写完整表单信息!');history.back();</script>" else: # 在这里添加提交表单信息的代码 return "<script>alert('提交成功!');window.location.href='/';</script>" # 将数据存储到 Excel 文件中 file_path = 'D:/data.xlsx' wb = load_workbook(file_path) ws = wb.active ws.append([line, date, model, lists, number, prod_date, shift, prod_line, responsible]) wb.save(file_path) return render_template('index2.html') @app.route('/history') def history(): # 从 Excel 文件中读取历史记录 file_path = 'D:/data.xlsx' df = pd.read_excel(file_path,keep_default_na=False) # 获取查询参数 query_date = request.args.get('date') query_line = request.args.get('line') query_model = request.args.get('model') # 进行查询 if query_date: df = df[df['确认日期'] == query_date] if query_line: df = df[df['确认线别'] == query_line] if query_model: df = df[df['异常机种'] == query_model] # 生成汇总图表 chart_data = df.groupby('异常现象').size().reset_index(name='count') chart_labels = chart_data['异常现象'].tolist() chart_values = chart_data['count'].tolist() return render_template('history.html', data=df.to_dict('records'), chart_labels=chart_labels, chart_values=chart_values) @app.route('/chart') def chart(): return render_template('chart.html') if __name__ == '__main__': app.run(debug=True)
这段代码看起来没有问题,但如果你想让历史记录查询更加精确,可以考虑使用 Pandas 的过滤功能,例如:
```python
# 从 Excel 文件中读取历史记录
file_path = 'D:/data.xlsx'
df = pd.read_excel(file_path, keep_default_na=False)
# 获取查询参数
query_date = request.args.get('date')
query_line = request.args.get('line')
query_model = request.args.get('model')
# 进行查询
conditions = []
if query_date:
conditions.append(df['确认日期'] == query_date)
if query_line:
conditions.append(df['确认线别'] == query_line)
if query_model:
conditions.append(df['异常机种'] == query_model)
if conditions:
df = df[pd.concat(conditions, axis=1).all(axis=1)]
```
这样可以实现多条件过滤,只显示符合条件的历史记录。