maxcutler / python-wordpress-xmlrpc

Python library for WordPress XML-RPC integration

Home Page:http://python-wordpress-xmlrpc.rtfd.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

xml.parsers.expat.ExpatError

brupelo opened this issue · comments

Hi,

this issue has been already commented & closed but I'm still unsure what was the final solution when this error is spawn:

xml.parsers.expat.ExpatError: XML or text declaration not at start of entity: line 2, column 0

To solve it manually right now I just need to add a custom Transport subclass like this:

class CustomTransport(Transport):

    def parse_response(self, response):
        # read response data from httpresponse, and parse it

        # Check for new http response object, else it is a file object
        if hasattr(response, 'getheader'):
            if response.getheader("Content-Encoding", "") == "gzip":
                stream = GzipDecodedResponse(response)
            else:
                stream = response
        else:
            stream = response

        p, u = self.getparser()

        while 1:
            data = stream.read(1024)
            data = data.strip()
            if not data:
                break
            if self.verbose:
                print "body:", repr(data)
            p.feed(data)

        if stream is not response:
            stream.close()
        p.close()

        return u.close()

Client(db,user,pw, transport=CustomTransport())

The thing is, this should be implement somehow in the python-wordpress-xmlrpc library. But first it should be identified when it's needed to use the custom transport.

On my side it happens using py2.7.10 and latest wp version Versión 4.5.2.

Anyway, what's the best solution for this?

Thanks

Also getting similar error: "xml.parsers.expat.ExpatError: not well-formed (invalid token): line 2782, column 75" - I am assuming because of "&" not converted to "&" in some of my titles but not sure.

I'm having the same problem with 4.6.1

I am having the same problem with wordpress 4.7.4. Which base class are you using for Transport?

@webermarcolivier it's from xmlrpclib

from xmlrpclib import Transport, GzipDecodedResponse

Thanks for this solution @brupelo !