[Zope-dev] [Zope-CMF] Weird UnicodeDecodeError with zope.formlib

Charlie Clark charlie.clark at clark-consulting.eu
Sun Dec 2 15:08:44 UTC 2012


Am 30.11.2012, 18:21 Uhr, schrieb Charlie Clark  
<charlie.clark at clark-consulting.eu>:

> Let me explain: in pdb I have access to request.form which is where I  
> can see the difference. With Sentry I can only see the raw body of the  
> request. I may simply have not understood well enough how to use it to  
> inspect what's happening.
>  I raise an exception in both cases in the forms' validate method.
>  Do you see this until you extract it first from the request object?
>   You are not having one form saying fieldname:string and the other just
> fieldname?
>  No, they are all zope.formlib/zope.schema fields so there is no  
> additional marshalling.

I have finally tracked down the problem: I seem to have been bitten by a  
change in zope.formlib 4.1.

There are two solutions: either extend a form's update method with the  
something like the following:

    def update(self):
	from Products.Five.browser.decode import processInputs
	from ZPublisher import HTTPRequest
         # XXX: if we don't set default_encoding explicitly, main_template  
might
         #      set a different charset
         self.request.RESPONSE.setHeader('Content-Type',
             'text/html; charset=%s' % HTTPRequest.default_encoding)
         # BBB: for Zope < 2.14
         if not getattr(self.request, 'postProcessInputs', False):
             processInputs(self.request, [HTTPRequest.default_encoding])
         super(_EditFormMixin, self).update()

Or, more simply, base forms on those provided by five.formlib.formbase

Thanks to yuppie for fixing this in the CMF.

I can confirm that this also works with Internet Explorer.

Charlie
-- 
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Kronenstr. 27a
Düsseldorf
D- 40217
Tel: +49-211-600-3657
Mobile: +49-178-782-6226


More information about the Zope-Dev mailing list