Comment 0 for bug 130857

Revision history for this message
Eleanor Berger (intellectronica) wrote :

In a test, I assign a unicode string with some non-ascii characters to the value of a field, and submit the form. I then get the following error (fragment):

      File "/home/tom/canonical/lp-branches/bug-129948/lib/zope/testbrowser/browser.py", line 568, in click
        self.browser._clickSubmit(self.mech_form, self.mech_control, (1,1))
      File "/home/user/project/lib/zope/testbrowser/browser.py", line 357, in _clickSubmit
        self.mech_browser.open(form.click(
      File "/usr/lib/python2.4/site-packages/ClientForm.py", line 2935, in click
        self._request_class)
      File "/usr/lib/python2.4/site-packages/ClientForm.py", line 3141, in _click
        return control._click(self, coord, return_type, request_class)
      File "/usr/lib/python2.4/site-packages/ClientForm.py", line 2299, in _click
        r = form._switch_click(return_type, request_class)
      File "/usr/lib/python2.4/site-packages/ClientForm.py", line 3209, in _switch_click
        req_data = self._request_data()
      File "/usr/lib/python2.4/site-packages/ClientForm.py", line 3192, in _request_data
        self.controls[control_index]._write_mime_data(mw, k, v)
      File "/usr/lib/python2.4/site-packages/ClientForm.py", line 1136, in _write_mime_data
        f.write(value)
    UnicodeEncodeError: 'ascii' codec can't encode character u'\xab' in position 0: ordinal not in range(128)

To behave more like a real browser, the test browser should automatically encode its content, trying to get the desired encoding from the form, or if that fails, from the page or from a sensible default (utf-8?).