@restAPI.route("/api/smartbiosdb-fw",methods=['POST','PUT'])
def smartbiosdbfw_operations():
import pandas as pd
# db_object = DbPipeline()
try:
logger.info("Smartbios accessed")
engine = get_scheduling_db_engine()
db_object = DbPipeline(engine=engine)
# db_object.engine = engine.connect()
print('Db connection successful')
data = request.json
operation = request.args.get('operation')
if operation == 'insertToSmartbiosCluster':
df = pd.DataFrame(data)
db_object.insert_to_smartbios_cluster(df)
logger.info("Data Inserted...")
return jsonify({'message':'Data inserted successfully'})
elif operation == 'insertToSmartbiosClusterIdMapping':
df = pd.DataFrame(data)
db_object.insert_to_smartbios_cluster_id_mapping(df)
return jsonify({'message': 'Data inserted into smartbios_cluster_id_mapping successfully'})
elif operation == 'insertToSmartbiosClusterKeywordMapping':
df = pd.DataFrame(data)
db_object.insert_to_smartbios_cluster_keyword_mapping(df)
return jsonify({'message': 'Data inserted into smartbios_cluster_keyword_mapping successfully'})
elif operation == 'insertToSmartbiosClusterExpertMapping':
df = pd.DataFrame(data)
db_object.insert_to_smartbios_cluster_expert_mapping(df)
return jsonify({'message': 'Data inserted into smartbios_cluster_expert_mapping successfully'})
elif operation == 'updateSmartbiosCluster':
df = pd.DataFrame(data)
db_object.update_smartbios_cluster(df)
return jsonify({'message': 'Data updated in smartbios_cluster successfully'})
else:
return jsonify({'error': 'Invalid operation'})
except Exception as e:
return jsonify({'error':str(e)})
这是我的 API,我尝试使用 http://localhost:5001/api/smartbiosdb-fw?operation=insertToSmartbiosCluster 访问它。当我尝试执行此操作时,我收到 400 Bad 请求。任何见解都会非常有帮助。
由于没有提到您如何尝试访问 API(浏览器、邮递员等),我假设您将链接放入浏览器中。
这将导致问题,因为您的端点仅支持
POST/PUT
并且您正在执行 GET
请求(浏览器默认)。
尝试使用 Postman 或 cURL 访问 API,方法为
POST/PUT
。或者在您的 API 中添加 GET
功能。取决于您的用例。