Error on upgrading from .9.6 when touching Headers in response

4 views
Skip to first unread message

Jonathan Vanasco

unread,
Mar 12, 2009, 6:06:48 PM3/12/09
to pylons-discuss
in .9.6 setting headers like this worked:
response.headers['Content-Type'] = 'application/ms-excel'

in .9.7 , anything i do to them is met with this
AttributeError: You cannot access Response.unicode_body unless charset
is set

looking at the new webob docs,

i tried doing
response.charset = 'utf8'

but that didn't work either.

so then i tried setting response.content_type , which worked

BUT

i also needed to set response.headers['Content-Disposition']

response.content_disposition ended up working, but its not documented
in webob

and these changes in how headers are affected are wholly undocumented
in the migration docs

Jonathan Vanasco

unread,
Mar 12, 2009, 6:20:10 PM3/12/09
to pylons-discuss
to add:

response.content_disposition 'works' in that it doesn't cause an
error. but it's not respected.

i've yet to test headers for 'cache-control' , 'pragma' , and
'expires'.

needless to say, this is a very annoying bug/behavior change.

Philip Jenvey

unread,
Mar 13, 2009, 9:14:54 PM3/13/09
to pylons-...@googlegroups.com

On Mar 12, 2009, at 3:06 PM, Jonathan Vanasco wrote:

>
> in .9.6 setting headers like this worked:
> response.headers['Content-Type'] = 'application/ms-excel'
>
> in .9.7 , anything i do to them is met with this
> AttributeError: You cannot access Response.unicode_body unless charset
> is set

Response actually determines the charset value lazily via the Content-
Type header -- since you didn't specify one its value was reset.
response.content_type is the smarter, shorthand version, that
maintains the charset.

It looks like the old Response actually had the same behavior, it was
just less strict about returning unicode values when there was no
charset. Also, assuming you returned the result of a render call --
render returns unicode now whereas before it returned a raw str.

Since there's a few things involved here I don't think we can make it
seamlessly backwards compatible. This would also work:

response.headers['Content-Type'] = 'application/ms-excel; charset=%s'
response.charset

But this is obviously nicer:

response.content_type = 'application/ms-excel'

Apparently Response allows assignment of arbitrary attributes, so even
though it doesn't support content_disposition, it didn't fail. I have
no idea why it does this, I'd rather it fail fast. We'll have to ask
Ian.

I've added actual .content_disposition support to WebOb trunk.

--
Philip Jenvey

Jonathan Vanasco

unread,
Mar 14, 2009, 12:24:01 PM3/14/09
to pylons-discuss
so basically we mostly just need a docs change to the 'migrating to
0.9.7' instructions

Philip Jenvey

unread,
Mar 14, 2009, 8:24:20 PM3/14/09
to pylons-...@googlegroups.com

On Mar 14, 2009, at 9:24 AM, Jonathan Vanasco wrote:

>
> so basically we mostly just need a docs change to the 'migrating to
> 0.9.7' instructions

Ok, done. Feel free to add to my change:

http://wiki.pylonshq.com/pages/diffpages.action?pageId=11174779&originalId=15302939

--
Philip Jenvey

Reply all
Reply to author
Forward
0 new messages