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

Python3.8 DocumentReader bug #50

Open
mathijswesterhof opened this issue Dec 5, 2019 · 1 comment
Open

Python3.8 DocumentReader bug #50

mathijswesterhof opened this issue Dec 5, 2019 · 1 comment

Comments

@mathijswesterhof
Copy link

mathijswesterhof commented Dec 5, 2019

in the dowloader of the suds reader there is an issue where the documentReader opens a new url that is not cached. It tries to download the url data, however the open function of the documentStore resolves that url and returns content instead of the file-handle. This is a bytestream. this bytestream has no read function. therefore when fp is not empty it generates an exception.

current code

    def download(self, url):
        store = DocumentStore()
        fp = store.open(url)
        if fp is None:
            fp = self.options.transport.open(Request(url))
        content = fp.read()
        fp.close()
        ctx = self.plugins.document.loaded(url=url, document=content)
        content = ctx.document
        sax = Parser()
        return sax.parse(string=content)

working solution

    def download(self, url):
        store = DocumentStore()
        fp = store.open(url)
        if fp is None:
            fp = self.options.transport.open(Request(url))
            content = fp.read()
            fp.close()
        else:
            content = fp
        ctx = self.plugins.document.loaded(url=url, document=content)
        content = ctx.document
        sax = Parser()
        return sax.parse(string=content)

The store.open() function can either return the bytestream (can be empty) or generate an exception. it has no option to return a file-handle. I am by far no expert on suds, can anyone verify this problem and help with a proper solution?

@cackharot
Copy link
Owner

Can you create a PR if this is required for all Python 3.x versions?

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

No branches or pull requests

2 participants