Problems after upgrading to 2.9.12

86 views
Skip to first unread message

naveed

unread,
Mar 1, 2015, 7:36:02 PM3/1/15
to web...@googlegroups.com
I was running a version 2.8.x without any trouble except that the forgot email feature was not working. I upgraded to 2.9.12 and my index page is being rendered as text (the source is being displayed on the browser). The content-type is showing up as json instead of html. I made NO changes to the application in months. After manually setting

response.headers['Content-Type'] = 'text/html'

in the index controller, the page renders correctly as HTML. But an ajax response that was returning JSON is failing on both Chrome and Firefox. Firefox shows a this error message:

SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data

Upon further investigation, it appears that the return is now actually JSON and it wasn't earlier, the content-type is JSON now. Something's changed with the content-type and is breaking previously working applications.

Niphlod

unread,
Mar 2, 2015, 3:41:00 AM3/2/15
to web...@googlegroups.com
it's a bug that got fixed.
You used to rely on response.json() to return a string, while it had to return a javascript object. 
Now response.json() sets the content-type header to application/json as it is supposed to.

Naveed Ahmed

unread,
Mar 2, 2015, 2:05:31 PM3/2/15
to web...@googlegroups.com
Makes sense for the json response, but why is the index which uses an html view returning as json?
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/9TZA25peXTE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niphlod

unread,
Mar 2, 2015, 2:56:52 PM3/2/15
to web...@googlegroups.com
that's definitely not related to the upgrade. that being said, if you can show some code with an app that reproduces the issue, I'll be glad to pinpoint the cause

Naveed Ahmed

unread,
Mar 2, 2015, 6:09:47 PM3/2/15
to web...@googlegroups.com
Looks like it’s caused by this line of code in index.html in the welcome app:
 
{{=(response.json(['foo', {'bar': ('baz', None, 1.0, 2)}])) }}

Niphlod

unread,
Mar 3, 2015, 5:21:58 AM3/3/15
to web...@googlegroups.com

Naveed Ahmed

unread,
Mar 3, 2015, 2:59:59 PM3/3/15
to web...@googlegroups.com
Sorry, I should have been more clear. It’s caused by adding the line
 
{{=(response.json(['foo', {'bar': ('baz', None, 1.0, 2)}])) }}
 
in to the existing index.html
 
From: Niphlod
Sent: Tuesday, March 03, 2015 4:21 AM
Subject: Re: [web2py] Re: Problems after upgrading to 2.9.12
 
--

Niphlod

unread,
Mar 3, 2015, 3:10:25 PM3/3/15
to web...@googlegroups.com
then, it's exactly as I said: the improper use of response.json.

Naveed Ahmed

unread,
Mar 3, 2015, 3:21:48 PM3/3/15
to web...@googlegroups.com
Ok, how do I convert a python object to a json object in the view?
 
From: Niphlod
Sent: Tuesday, March 03, 2015 2:10 PM
Subject: Re: [web2py] Re: Problems after upgrading to 2.9.12
 
--

Niphlod

unread,
Mar 3, 2015, 3:36:48 PM3/3/15
to web...@googlegroups.com
it should be done in the controller, the view is where you present the data, not where you transform it.

anyway, if you want to hurt yourself, you can do

{{import json as myjson}}
{{=myjson.dumps(['a', 'b', 'c', {1: 'x'}])}}



Naveed Ahmed

unread,
Mar 3, 2015, 3:42:12 PM3/3/15
to web...@googlegroups.com
Thanks. I did go along this path, but I was trying to use a database rows object, I need to iterate through it in the view, but javascript needs to iterate through it as well. The response json method works well for this, but as you mention it’s not a response. Is there a similar web2py method that can be used to convert the rows object to JSON?
 
From: Niphlod
Sent: Tuesday, March 03, 2015 2:36 PM
Subject: Re: [web2py] Re: Problems after upgrading to 2.9.12
 

Leonel Câmara

unread,
Mar 3, 2015, 3:53:55 PM3/3/15
to web...@googlegroups.com
You can do this

{{from gluon.serializers import json}}
{{=XML(json(myrows), sanitize=False)}}

Naveed Ahmed

unread,
Mar 3, 2015, 3:59:32 PM3/3/15
to web...@googlegroups.com
This helps a lot, thank you.
Reply all
Reply to author
Forward
0 new messages