Ticket #617 (closed defect: invalid)

Opened 16 months ago

Last modified 16 months ago

jsonify needs charset

Reported by: Shannon -jj Behrens Owned by: bbangert
Priority: normal Milestone: 1.0
Component: helpers Version: 0.9.7
Severity: normal Keywords:
Cc: jjinux@…

Description

Looking at the jsonify decorator's source code, I see:

pylons.response.headers['Content-Type'] = 'application/json'

My experience has been that WebOb? freaks out and raises an exception if you don't set a charset:

pylons.response.headers['Content-Type'] = 'application/json; charset=utf-8'

Change History

Changed 16 months ago by Shannon -jj Behrens

Hmm, sometimes it works. It might vary based on the data. I'm not sure yet.

Changed 16 months ago by Shannon -jj Behrens

Here's the error I'm getting:

URL: http://localhost:5000/api/recommendations?format=JSON&atom=http%3A%2F%2Fwww.kk.org%2Fcooltools%2Farchives%2F000587.php&project=kk&field=url&max_recommendations=3&jsonp=showRecommendations
File '/opt/local/lib/python2.5/site-packages/WebError-0.10.1-py2.5.egg/weberror/evalexception.py', line 431 in respond
  app_iter = self.application(environ, detect_start_response)
File '/opt/local/lib/python2.5/site-packages/Beaker-1.3.1-py2.5.egg/beaker/middleware.py', line 70 in __call__
  return self.app(environ, start_response)
File '/opt/local/lib/python2.5/site-packages/Beaker-1.3.1-py2.5.egg/beaker/middleware.py', line 149 in __call__
  return self.wrap_app(environ, session_start_response)
File '/opt/local/lib/python2.5/site-packages/Routes-1.10.3-py2.5.egg/routes/middleware.py', line 130 in __call__
  response = self.app(environ, start_response)
File '/opt/local/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 '/opt/local/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 '/Users/jj/Work/24hrdiner/svn/trunk/wwwaiter/wwwaiter/lib/base.py', line 27 in __call__
  return WSGIController.__call__(self, environ, start_response)
File '/opt/local/lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 236 in __call__
  py_response.unicode_body = py_response.unicode_body + \
File 'build/bdist.macosx-10.5-i386/egg/webob/__init__.py', line 1766 in _unicode_body__get
AttributeError: You cannot access Response.unicode_body unless charset is set

Let me see if I can get a standalone repro.

Changed 16 months ago by Shannon -jj Behrens

  • status changed from new to closed
  • resolution set to invalid

Never mind. It turns out that there was a bad interaction between the jsonify decorator and some code I had for doing jsonp. I changed my code so that when I do jsonp, I set Content-Type to 'test/javascript; charset=utf-8'. When I'm not doing jsonp, the jsonify decorator works just fine.

Note: See TracTickets for help on using tickets.


Powered by Pylons - Contact Administrators