Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error while trying to add header with Set-Cookie in GAE

I am trying to include external python module in my project for working with sessions. It's named gmemsess.py. It tries to add Set-Cookie header in the response and an error appears:

rh.response.headers.add_header('Set-Cookie','%s=%s; path=/;'%(name,self._sid))
AttributeError: HeaderDict instance has no attribute 'add_header'

I read documentation and everything seems ok, but it doesn't work. Why this error can appear? Also, I use webapp2 to manage subdomains. May be there is something goes wrong because of this?

like image 839
Sergei Basharov Avatar asked Mar 02 '26 11:03

Sergei Basharov


1 Answers

The headers.add_header method should absolutely work if you are using stock AppEngine, but I am guessing that you are using a framework -- and there are plenty of them, like Bottle -- that uses a custom replacement for webob's Response object.

A little bit of time with Google reveals that there is at least one identifiable class called HeaderDict that extends MultiDict, and I think that is what you are dealing with. In that case, you should to into gmemsess.py and change the line

rh.response.headers.add_header('Set-Cookie','%s=%s; path=/;'%(name,self._sid))

to read

rh.response.headers['Set-Cookie'] = '%s=%s; path=/;'%(name,self._sid)

That should fix you right up.

like image 98
Adam Crossland Avatar answered Mar 04 '26 23:03

Adam Crossland