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

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python在Swagger Web服务响应中放置转义符号相关的知识,希望对你有一定的参考价值。

我有一个存储过程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
'
                      'Conection DB:' + db_str + '
'
                                                  '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在Swagger Web服务响应中放置转义符号的主要内容,如果未能解决你的问题,请参考以下文章

如何在 Web API 2 控制器中放置多个 GET 方法?

在 Plotly Dash 图表中放置刻度标签 - Python

wpf 中scrollviewer 中放置个LISTBOX,当焦点在LISTBOX时候,滚动鼠标不响应Scrollviewer的鼠标滚动

如何在 tkinter ~ python 中放置在网格中的两个小部件之间添加空间?

Tailwind:如何在导航栏父 div 中放置图像

在 Bitnami LAMP Ubuntu 服务器中放置网站文件的位置