我有一个oracle过程,当接收到一些参数时,将结果抛出具有JSON格式的字符串,如下所示:
lm.out <- lm(Humerus ~ $Radius,data=new_data)
newx = seq(min(new_data$Radius),max(new_data$Humerus),by = 0.05)
conf_interval <- predict(lm.out, newdata=data.frame(Radius=newx), interval="confidence",level = 0.95)
plot(new_data$Radius, new_data$Humerus, xlab="Radius", ylab="Humerus", main="Regression")
abline(lm.out, col="lightblue")
lines(newx, conf_interval[,2], col="blue", lty=2)
lines(newx, conf_interval[,3], col="blue", lty=2)
此过程是从我使用FlaskResfutl开发的Python Web服务中调用的,以创建通用控件,这是代码:
{"list_pais": [ {"pais":"URUGUAY"},{"pais":"ARGENTINA"},{"pais":"PARAGUAY"},{"pais":"VENEZUELA"}] }
但是在执行它时,会产生以下错误:
import cx_Oracle
import json
from app import APP
import log
import graypy
import database
from flask_restplus import Api, Resource, fields
with open('./config/config_countries.json', 'r') as config_file:
config = json.load(config_file)
log.init()
#Se inicializa la base de datos
#Importando de database la conexión a la BD
database.init()
#Invoca al archivo de configuración
with open('./config/config_countries.json', 'r') as config_file:
config = json.load(config_file)
with open('./config/config_general.json', 'r') as config_file:
config_general = json.load(config_file)
srv_name = config["CONFIG"]["LOG_TAG"]
db_str = config["CONFIG"]["DB"]
max_return = config_general["CONFIG"]["MAX_RETURN"]
limite = config["CONFIG"]["LIMIT_PER_SECOND"]
api = Api(APP, version='1.0', title=srv_name,
description='getCountries de Callejero Predictivo\n'
'Conexión a BD:' + db_str + '\n'
'Cantidad máxima de invocaciones por segundo:' + limite)
ns = api.namespace('getCountry', description='getCountries de Callejero Predictivo')
md_respuesta = {'pais': fields.String(required=True, description='Agrupador de Paises'), 'list_pais': fields.Nested(fields.String)}
@ns.route('/<string:country>')
@ns.response(200, 'Success')
@ns.response(404, 'Not found')
@ns.response(429, 'Too many request')
@ns.param('country', 'Introducir Cadena de Caracteres para el Pais')
class getCountryClass(Resource):
@ns.doc('getCountry')
@ns.marshal_list_with(md_respuesta)
def post(self, country):
try:
cur = database.db.cursor()
listOutput = cur.var(cx_Oracle.STRING)
cur.callproc('PREDICTIVO.get_pais', (country, max_return, listOutput))
except Exception as e:
database.init()
if database.db is not None:
log.err('Reconexion OK')
cur = database.db.cursor()
listOutput = cur.var(cx_Oracle.STRING)
cur.callproc('PREDICTIVO.get_pais', (country, max_return, listOutput))
else:
log.err('Sin conexion a la base de datos')
listOutput = None
return listOutput, 200
,我找不到解决方法。 有人可以给我提示解决的线索吗?
这是生产中很好的版本,无需大张旗鼓 https://github.com/alemarchan/sources_predictivo_prod
答案 0 :(得分:0)
查看https://flask-restplus.readthedocs.io/en/stable/_modules/flask_restplus/swagger.html和https://flask-restplus.readthedocs.io/en/stable/quickstart.html
注册的模型不能是字典,您需要一个模型,尝试替换
md_respuesta = {'pais': fields.String(required=True, description='Agrupador de Paises'), 'list_pais': fields.Nested(fields.String)}
通过
md_respuesta = api.model('Pais', {'pais': fields.String(required=True, description='Agrupador de Paises'), 'list_pais': fields.Nested(fields.String)})