ASP and Cookie problem with Python

Dave Rogers drogers at sequoianet.com
Wed May 2 13:48:28 EDT 2001


I'm using Python/ASP to power a "large" web site.

At one point we would like to set a simple cookie.

I have a wrapper method in a web page superclass that does this:

def setCookie(self,name,value):
  if self._wrote: # have we written to the buffer
   self.write('Trying to set Cookie AFTER writing regular content')
  elif type(self._response) == types.InstanceType:
   C = Cookie.SmartCookie()
   C[name] = value
   cookieText = str(C.output()[12:]) + 'expires=Sat, 01-Jan-2033
00:00:00 GMT'
   self._response.AddHeader("Set-Cookie",cookieText)

The response object is assigned to self._response and the self._wrote is
a boolean flag used to determine if any output has already been written.

The strange thing is that this problem is NOT consistently
reproducible.  It happens about 5% of the time the page that sets the
cookie is accessed.

The error I get is as follows:

"""
(-2147352567, 'Exception
occurred.', (0, 'Response object', '006~ASP 0156~Header Error~The HTTP
headers are already written to the client
browser. Any HTTP header modifications must be made before writing page
content.', '', 0, -2147467259), None)

Python ActiveX Scripting Engine error 'ASP 0156 : 80020009'

Header Error

?, line 0

return
self._get_good_object_(apply(self._oleobj_.Invoke,allArgs),self._olerepr_.defaultDispatchName,None)

The HTTP headers are already written to the client browser. Any HTTP
header modifications must be made before writing page
content.
"""

The issue is that I have not written output.  This error is given when I
have enable buffering set to OFF in IIS.  When it is set to TRUE,
allegedly, you can add headers after you have written content, BUT, I
have noticed that I get an "HTTP 1.1 500 Error" about 5% of the time I
hit the page.

How does anyone set cookies using ASP reliably?  I want the cookie to
stick around after the session, so I cannot use the Session object.

Thanks,

Dave Rogers
drogers at sequoianet.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20010502/f42076f2/attachment.html>


More information about the Python-list mailing list