python-wordpress-xmlrpc icon indicating copy to clipboard operation
python-wordpress-xmlrpc copied to clipboard

xml.parsers.expat.ExpatError

Open brupelo opened this issue 8 years ago • 4 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

brupelo avatar May 24 '16 11:05 brupelo

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.

ajohnclark avatar May 26 '16 20:05 ajohnclark

I'm having the same problem with 4.6.1

jonathan-s avatar Sep 11 '16 22:09 jonathan-s

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

webermarcolivier avatar May 09 '17 13:05 webermarcolivier

@webermarcolivier it's from xmlrpclib

from xmlrpclib import Transport, GzipDecodedResponse

Thanks for this solution @brupelo !

jamesbrink avatar Jun 05 '17 13:06 jamesbrink