Python在Swagger Web服务响应中放置转义符号

问题描述 投票:0回答:1

我有一个存储过程Oracle,它返回一个包含JSON格式信息的变量类型CLOB。该变量在Python中捕获了她,并将其返回给Web服务。存储过程输出具有以下样式:

{"role":"Proof_Rol","identification":"31056235002761","class":"Proof_Clase","country":"ARGENTINA","stateOrProvince":"Santa Fe","city":"Rosario","locality":"Rosario","streetName":"Brown","streetNr":"2761","x":"5438468,710153","y":"6356634,962204"}

但是在Python服务出口处,它显示如下:

{"Atributos": "{\"role\":\"Proof_Rol\",\"identification\":\"31056235002761\",\"class\":\"Proof_Clase\",\"country\":\"ARGENTINA\",\"stateOrProvince\":\"Santa Fe\",\"city\":\"Rosario\",\"locality\":\"Rosario\",\"streetName\":\"Brown\",\"streetNr\":\"2761\",\"x\":\"5438468,710153\",\"y\":\"6356634,962204\"}"}

enter image description here

有谁知道如何防止转义字符在服务的退出处输入该字符串?

我的Python代码的一部分是:

api = Api(APP, version='1.0', title='attributes API',
          description='Attibute Microservice\n'
                      'Conection DB:' + db_str + '\n'
                                                  'Max try:' + limite)
 ns = api.namespace('attributes', description='Show descriptions of an object')

md_respuesta = api.model('attributes', {
    'Attribute': fields.String(required=True, description='Attribute List')
})

class listAtriClass:
    Attribute = None

@ns.route('/<string:elementId>')
@ns.response(200, 'Success')
@ns.response(404, 'Not found')
@ns.response(429, 'Too many request')
@ns.param('elementId', 'Id Element (ej:31056235002761)')
class attibuteClass(Resource):
    @ns.doc('attributes')
    @ns.marshal_with(md_respuesta)
    def post(self, elementId):
        try:
            cur = database.db.cursor()
            listOutput = cur.var(cx_Oracle.CLOB)
            e, l = cur.callproc('attributes.get_attributes', (elementId, listOutput))
        except Exception as e:
            database.init()
            if database.db is not None:
                log.err('Reconection OK')
                cur = database.db.cursor()
                listOutput = cur.var(cx_Oracle.CLOB)
                e, l = cur.callproc('attributes.get_attributes', (elementId, listOutput))
                print(listOutput)
            else:
                log.err('Conection Fails')
                listOutput = None
        result = listAtriClass()
        result.Attribute =listOutput.getvalue()
        print(result.Attribute)
        return result, 200
python flask swagger
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.