Skip to content

Getting 404 on loading https://schemas.xmlsoap.org/soap/encoding/ #1417

Open

Description

@junctionapps

Some schemas include a namespace like

xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"

It seems like either the site hosting that occasionally goes down, or is throttling requests in some way. As a result, Zeep throws a 404 (or in some cases a 403) error when it attempts to load that file.

What I'm posting here is likely not the best way to overcome this, but maybe it will help someone else who comes along.

I'm using a Django application here, so this will be a little bit Django centric, but should be easy enough to adapt to your needs. I've been able to get a copy of the contents of https://schemas.xmlsoap.org/soap/encoding/ and saved them locally inside of my app folder and named the file soap-encodings.xml. After that I created my own Transport class and overwrote the load method and added a little bit for recognizing if it is the offending schema.

class LocalSchemaTransport(Transport):
    """
    Overrides Transport to accommodate local version of schema for http://schemas.xmlsoap.org/soap/encoding/
    """
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def load(self, url):
        """Load the content from the given URL"""
        if not url:
            raise ValueError("No url given to load")

        scheme = urlparse(url).scheme
        if scheme in ("http", "https", "file"):

            if self.cache:
                response = self.cache.get(url)
                if response:
                    return bytes(response)

            # this url was causing some issues (404 errors); it is now saved locally for fast retrieval when needed
            if url == 'http://schemas.xmlsoap.org/soap/encoding/':
                base_dir = settings.BASE_DIR
                app_path = 'put_the_folder_of_appname_here'
                soap_encodings_file = base_dir / app_path / 'soap-encodings.xml'
                with open(soap_encodings_file, 'rb') as fh:
                    return fh.read()

            content = self._load_remote_data(url)

            if self.cache:
                self.cache.add(url, content)

            return content
        else:
            with open(os.path.expanduser(url), "rb") as fh:
                return fh.read()

Following that, to use this in your code, you do something like:

client = Client(wsdl,
                transport=LocalSchemaTransport(session=session,
                                               cache=InMemoryCache(),
                                               timeout=30))

If there is a way to do this with a provided argument I'd love to know it.

Feel free to close the ticket, just wanted to drop in one way to get around it.

Activity

  1. tswfi commented on Apr 30, 2024

    @tswfi

    Thanks, I was just hit by this also! Do you have the contents of the file? I'm getting 404 all the time from the site. I did check waybackmachine but I'm not 100% sure it does a 1:1 copy of xml that way...

  2. nc9 commented on Apr 30, 2024

    @nc9

    @tswfi I've mirrored it here:

    https://gist.github.com/nc9/8682e6cb7fa9398cfe3de0b6e7ec99c9

    So many issues with WSDL files that I just make a local copy of the service WSDL file and then update the schema directly, and then point the client to that local copy of the WSDL

  3. junctionapps commented on Apr 30, 2024

    @junctionapps
    Author

    @tswfi
    soap-encodings-schemas.xmlsoap.org.txt
    Saved as a txt for upload to github purposes.

  4. Steve-Roderick commented on May 1, 2024

    @Steve-Roderick

    wow - @junctionapps - the LocalSchemaTransport worked! Yr a legend - thank you!

    I saved the xml file locally and then modified this part of your code to adapt:

    From

    app_path = 'put_the_folder_of_appname_here'
    soap_encodings_file = base_dir / app_path / 'soap-encodings.xml'
    ...
    

    To

    Get path to this script.
    base_dir = os.path.dirname(os.path.realpath(__file__))
    
    # Save soap-encodings.xml locally in the same directory as the script.
    soap_encodings_file = os.path.join(base_dir, 'soap-encodings.xml')
    

    Thanks again!

  5. austin-wentz commented on May 1, 2024

    @austin-wentz

    Ran into this issue as well. Another possible solution that doesn't require a custom Transport is to warm the cache with any WSDL files you want. Something like

    for url, filename in SCHEMAS_TO_CACHE:
        with open(filename, "rb") as fh:
            cache.add(url, fh.read())
    
  6. tswfi commented on May 2, 2024

    @tswfi

    @mvantellingen what do you think, maybe zeep could ship with some of those default documents that do not change that often and always use the local copies?

  7. ahahamyan commented on May 2, 2024

    @ahahamyan

    Just reloaded and integration appears to be working now - https://schemas.xmlsoap.org/soap/encoding/ is coming back. 404 issue is resolved looks like.

  8. mvantellingen commented on Oct 13, 2024

    @mvantellingen
    Owner

    I think we should include these default schema's with zeep (and detect if these are loaded) PR's welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions