No encoding set for XML-RPC responses

Bug #142672 reported by Bug Importer
8
This bug affects 2 people
Affects Status Importance Assigned to Milestone
Zope 2
Invalid
Low
Unassigned

Bug Description

The XML returned by Zope as a response to an XML-RPC request contains no "encoding=" attribute to the <?xml?> header ...

This means that when there is high-bit latin 1 characters, such as accents, clients die (Including when using xmlrpclib as a client).

The problem is in lib/python/ZPublisher/xmlrpc.py, lines 110 and popssibly 101 also.

The calls to xmlrpclib.dumps() do not include the "encoding=" parameter.

Also because this is a function and not a method of a class, I can't seem to be able to easily monkey patch it :(

The simple solution would be to hardcode the most common charset in there ( i.e. encoding='iso-8859-1' ).

A better way would be to use the information provided by the locale module. Something like:

encoding=locale.getlocale()[1]

Would do ...

Admitedly however I'm not familiar with internal Zope internationalization, so there might be a better way through some Zope provided function ? (Though I don't see any first hand).

Revision history for this message
Jens Quade (snej) wrote :

XMLRPC requests are sent as "text/xml", which means the XML document is us-ascii, unless stated otherwise in the Content-Type HTTP-Header (see RFC3023 for details).
The XML declaration in the document does not declare the encoding. Maybe it's easier to encode the XML stream in us-ascii than to figure out the correct encoding?

Revision history for this message
Andreas Jung (ajung) wrote :

Nonsense.
The default encoding for XML documents is UTF8. This
has absolutely nothing to do with any information within
the HTTP header. If the 'encoding' attribute within the XML
preamble is not present then the default encoding UTF-8 applies...nothing else.

Revision history for this message
Hanno Schlichting (hannosch) wrote :

Judging from Andreas comment, there's actually nothing wrong with the code in Zope2 - which has remained pretty much unchanged in all the years.

Changed in zope2:
status: New → Invalid
Revision history for this message
Nils Fredrik Gjerull (nfg) wrote :

The XML returned by Zope's xmlrpc should include a xml declaration containing the current encoding used by zope. Where I work now we have a lot of content in the iso-8859-1 encoding, so the xml default of UTF-8 is not appropriate. Retrieving content containing iso-8859-1 encoded characters results in a UnicodeDecodeError. In order for us to use xml-rpc we have to monkey patch the setBody method in ZPublisher.xmlrpc.Response.

The comment by Andreas was about declaring the encoding in the HTTP response, but that not the issue in this bug report. The issue is that the xml returned do not declare an encoding (e.g <?xml version="1.0" encoding="iso-8859-1"?>).

Changed in zope2:
status: Invalid → New
Revision history for this message
Jens Vagelpohl (dataflake-deactivatedaccount-deactivatedaccount) wrote :

Nils, please provide us with a traceback for the unpatched code and the patch you are applying as it's still unclear where the specific error is you are seeing.

By the way, Andreas _did_ speak about the XML preamble as well.

Changed in zope2:
status: New → Incomplete
importance: Medium → Low
Revision history for this message
Colin Watson (cjwatson) wrote :

The zope2 project on Launchpad has been archived at the request of the Zope developers (see https://answers.launchpad.net/launchpad/+question/683589 and https://answers.launchpad.net/launchpad/+question/685285). If this bug is still relevant, please refile it at https://github.com/zopefoundation/zope2.

Changed in zope2:
status: Incomplete → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.