Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed some type mismatches in case when mtom/xop is in incoming message #716

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shasoka
Copy link

@shasoka shasoka commented Nov 25, 2024

I'm building simple SOAP-service with Spyne 2.14 and a SOAP-client with Zeep 4.3.1 + pymtom_xop 0.0.2 on Python 3.10 as part of my university's homework.

I've faced the problem using Spyne for handling incoming MTOM/XOP attachments. There were multiple not handled exceptions, generally because of types mismatching and not-declared variables. I'm wondering how linter skipped such mistakes, anyways...

I tried my best to catch and handle them, so now it works almost fine. I still receive HTTP 500 for mp3 files (yeah, very strange), but for now I'll leave it as is 🫤

@shasoka
Copy link
Author

shasoka commented Nov 25, 2024

I'm building simple SOAP-service with Spyne 2.14 and a SOAP-client with Zeep 4.3.1 + pymtom_xop 0.0.2 on Python 3.10 as part of my university's homework.

I've faced the problem using Spyne for handling incoming MTOM/XOP attachments. There were multiple not handled exceptions, generally because of types mismatching and not-declared variables. I'm wondering how linter skipped such mistakes, anyways...

I tried my best to catch and handle them, so now it works almost fine. I still receive HTTP 500 for mp3 files (yeah, very strange), but for now I'll leave it as is 🫤

UPD: Found the source of HTTP 500 for mp3 and other "usually-huge" files.
By default spyne.server.wsgi.WsgiApplication has a constraint max_content_length=2 * 1024 * 1024. I changed it to 10 Mb while instancing an object:

# server/main.py

import logging
import sys

from spyne import Application, Fault, InternalError, ResourceNotFoundError
from spyne.protocol.soap import Soap11
from spyne.server.wsgi import WsgiApplication
from sqlalchemy.exc import NoResultFound
from twisted.internet import reactor
from twisted.python import log
from twisted.web.server import Site
from twisted.web.wsgi import WSGIResource

from core.config import MAIN_TNS
from core.db.defctx import on_method_call
from services.files import FileService
from services.users import UserService


class MyApplication(Application):
    def __init__(
        self, services, tns, name=None, in_protocol=None, out_protocol=None
    ):
        super().__init__(services, tns, name, in_protocol, out_protocol)

    def call_wrapper(self, ctx):
        try:
            return ctx.service_class.call_wrapper(ctx)

        except NoResultFound as e:
            log.msg("[EXCEPTION] " + e)
            raise ResourceNotFoundError(ctx.in_object)

        except Fault as e:
            log.msg("[EXCEPTION] " + e)
            raise

        except Exception as e:
            log.msg("[EXCEPTION] " + e)
            raise InternalError(e)


if __name__ == "__main__":
    logging.basicConfig(level=logging.DEBUG)
    observer = log.PythonLoggingObserver("twisted")
    log.startLogging(sys.stdout)

    application = MyApplication(
        [UserService, FileService],
        tns=MAIN_TNS,
        in_protocol=Soap11(validator="lxml"),
        out_protocol=Soap11(),
    )

    application.event_manager.add_listener("method_call", on_method_call)

    wsgi_app = WsgiApplication(
        application,
        max_content_length=10 * 1024 * 1024,
    )
    resource = WSGIResource(reactor, reactor, wsgi_app)
    site = Site(resource)
    reactor.listenTCP(8000, site, interface="127.0.0.1")  # noqa

    log.msg("🧼 Listening to http://127.0.0.1:8000")
    log.msg("📝 WSDL is at http://127.0.0.1:8000/?wsdl")

    sys.exit(reactor.run())  # noqa

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant