Trying to test a form in pylons and getting the following error when
calling form.submit()

TypeError: You cannot set the body to a unicode value without a
charset

The test code does the following in a class derived from
TestController and running under 'python setup.py nosetests'

1. call self.app.get to retrieve the form
2. modify 2 fields in the form
3. call form.submit() which throws the TypeError.


Below I'll include the code & the stack trace.

Thanks for your thoughts.

- Jeff


*************** CODE ********************
     def test_edit_update_iPhone(self):
          response=self.app.get('/product/fields/'+self.urn_iphone )
          form=response.forms['update_product_fields']

          print("************** test_edit_iPhone response  %s" %
response)
          assert form

          print("test_edit_iphone
response.forms['update_product_fields'] = %r" % form.fields)

          old_id=form.fields['edit_ap_id'][0].value
          print "*********************"
          print "current id = %r with class %r" % (old_id,
old_id.__class__)
          print "*********************"

          new_id=str(int(old_id) ^ 0xfffff)

          old_description=form.fields['edit_description'][0].value
          old_language=form.fields['edit_description'][0].value

          print("old_description is %r" % old_description)

          new_description=re.sub("[tT]he", "THE",
old_description.strip())

          print "new_id = %s with class %s" % (new_id,
new_id.__class__)
          print "new_description = %s with class %s" %
(new_description, new_description.__class__)

          response = form.submit()
          print("response = %s" % response)
          assert "Successfully" in response.c.product_response

***************** STACK TRACE *******************

======================================================================
ERROR: test_edit_update_iPhone
(gluten.tests.functional.test_products.TestProductsController)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jeff/source/gluten/gluten/tests/functional/
test_products.py", line 173, in test_edit_update_iPhone
    response = form.submit()
  File "build/bdist.linux-i686/egg/webtest/__init__.py", line 1100, in
submit
  File "build/bdist.linux-i686/egg/webtest/__init__.py", line 655, in
goto
  File "build/bdist.linux-i686/egg/webtest/__init__.py", line 208, in
post
  File "build/bdist.linux-i686/egg/webtest/__init__.py", line 188, in
_gen_request
  File "build/bdist.linux-i686/egg/webtest/__init__.py", line 310, in
do_request
  File "build/bdist.linux-i686/egg/webob/request.py", line 914, in
get_response
    application, catch_exc_info=True)
  File "build/bdist.linux-i686/egg/webob/request.py", line 886, in
call_application
    app_iter = application(self.environ, start_response)
  File "build/bdist.linux-i686/egg/webtest/lint.py", line 170, in
lint_app
    iterator = application(environ, start_response_wrapper)
  File "/home/jeff/gluten/Paste-1.7.2-py2.5.egg/paste/cascade.py",
line 130, in __call__
  File "/home/jeff/gluten/Paste-1.7.2-py2.5.egg/paste/registry.py",
line 350, in __call__
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
repoze.profile-1.1-py2.5.egg/repoze/profile/profiler.py", line 140, in
__call__
    _locals)
  File "/usr/lib/python2.5/cProfile.py", line 140, in runctx
    exec cmd in globals, locals
  File "<string>", line 1, in <module>
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
Pylons-0.9.7-py2.5.egg/pylons/middleware.py", line 201, in __call__
    self.app, environ, catch_exc_info=True)
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
Pylons-0.9.7-py2.5.egg/pylons/util.py", line 94, in
call_wsgi_application
    app_iter = application(environ, start_response)
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
WebError-0.10.1-py2.5.egg/weberror/evalexception.py", line 235, in
__call__
    return self.respond(environ, start_response)
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
WebError-0.10.1-py2.5.egg/weberror/evalexception.py", line 418, in
respond
    return self.application(environ, start_response)
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
Beaker-1.5.1-py2.5.egg/beaker/middleware.py", line 73, in __call__
    return self.app(environ, start_response)
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
Beaker-1.5.1-py2.5.egg/beaker/middleware.py", line 152, in __call__
    return self.wrap_app(environ, session_start_response)
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
Routes-1.11-py2.5.egg/routes/middleware.py", line 130, in __call__
    response = self.app(environ, start_response)
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
Pylons-0.9.7-py2.5.egg/pylons/wsgiapp.py", line 125, in __call__
    response = self.dispatch(controller, environ, start_response)
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
Pylons-0.9.7-py2.5.egg/pylons/wsgiapp.py", line 324, in dispatch
    return controller(environ, start_response)
  File "/home/jeff/gluten/gluten/lib/base.py", line 19, in __call__
  File "/home/jeff/source/gluten/lib/python2.5/site-packages/
Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py", line 284, in
__call__
    return response(environ, self.start_response)
  File "build/bdist.linux-i686/egg/webob/exc.py", line 248, in
__call__
    return self.generate_response(environ, start_response)
  File "build/bdist.linux-i686/egg/webob/exc.py", line 239, in
generate_response
    content_type=content_type
  File "build/bdist.linux-i686/egg/webob/response.py", line 94, in
__init__
    "You cannot set the body to a unicode value without a charset")
TypeError: You cannot set the body to a unicode value without a
charset
-------------------- >> begin captured logging << --------------------

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en.

Reply via email to