Как отладить тело запроса или атрибуты из spyne

Моя комплексная модель выглядит следующим образом. Я удалил ненужные сложные модели по некоторым причинам. Моя цель - вернуть ответ в соответствии с запросом. Для возврата надежного ответа я должен проверить элементы из запроса с атрибутом экземпляра из моей связанной таблицы.

import logging
from lxml import etree
from spyne import Application, rpc, ServiceBase, AnyDict
from spyne.protocol.soap import Soap11
from spyne.server.django import DjangoApplication
import uuid
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
from my_complex_models import Request1Type, Request91Type, CertificateMaximumType, CertificateMinimumType
from .models import MyTable

class MyIntegrationApiView(ServiceBase):
    @rpc(Request91Type,
         _returns=AnyDict,
         _out_variable_name="Response91")
    def Request91(ctx, request91type):
        try:
            logging.info(
                f'Initialized objects {str(request91type).encode("utf-8")}')
            b = etree.tostring(ctx.in_document, encoding='unicode')
            
            return {
                #appropriate data from my table 
                "data": MyTable.data
                ##########
            }
            
        except Exception as e:
            logging.info(f'Exception occurred: {str(e)}')

def on_method_return_string(ctx):
    ctx.out_string[0] = ctx.out_string[0].replace(b'soap11env', b'soap')
    ctx.out_string[0] = ctx.out_string[0].replace(b'tns', b'm')
    ctx.out_string[0] = ctx.out_string[0].replace(b'ID', b'm:ID')
    ctx.out_string[0] = ctx.out_string[0].replace(
        b'Code', b'm:Code')
    ctx.out_string[0] = ctx.out_string[0].replace(
        b'Name', b'm:Name')
    ctx.out_string[0] = ctx.out_string[0].replace(
        b'Place', b'm:Place')

MyIntegrationApiView.event_manager.add_listener('method_return_string',
                                                     on_method_return_string)
application = Application([MyIntegrationApiView],
                          'wsdl_url',
                          name='mybinding',
                          in_protocol=Soap11(validator='soft'),
                          out_protocol=Soap11(),
                          )

my_api_service = DjangoApplication(application)


def get_wsdl_file_my(request):

    with open('my.wsdl', 'r') as f:
        docs = f.read()
    return HttpResponse(docs, content_type='text/xml; charset=utf-8')


@csrf_exempt
def my_service_dispatcher(request):
    if request.get_full_path() in ('/MyWebService/russian/?wsdl',
                                   '/MyWebService/russian?wsdl'):
        return get_wsdl_file_russian(request)
    return my_api_service(request)

Выше приведен сниппет для моего мнения. Я отправляю случайный вывод словаря для тестирования. Он работает хорошо, но я не смог проверить его на валидность. Для решения этой проблемы мне нужен номер сертификата из запроса. Я видел один пример вроде этого: request91type.attr_name, но request91type возвращает None. Я решил эту проблему с помощью разбора ctx следующим образом etree.tostring(ctx.in_document, encoding='unicode'), но у меня есть другая проблема с разбором массива в xml и его сохранением. Я просмотрел несколько примеров, но у меня ничего не получилось.

вот мой wsdl файл :https://pastebin.com/RLtSnvwQ

Буду рад, если кто-то поможет мне или поделится полезными ссылками. Заранее спасибо.

Вернуться на верх