Re: Weird UnicodeDecodeError with zope.formlib

"Charlie Clark" <[email protected]>
Newsgroups gmane.comp.web.zope.cmf,gmane.comp.web.zope.devel
Organization Clark Consulting & Research
Message-ID <[email protected]>
Am 30.11.2012, 18:21 Uhr, schrieb Charlie Clark  
<[email protected]>:

> 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
_______________________________________________
Zope-CMF maillist  -  [email protected]
https://mail.zope.org/mailman/listinfo/zope-cmf

See https://bugs.launchpad.net/zope-cmf/ for bug reports and feature requests
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.