text: Q:
  
  Can't seem to access cookie in Python (2.4)
  
  I have a CGI script for which I've successfully set a cookie (which I can see in Firefox/Chrome!) which has (say) the name uid and the content 1. I don't seem to understand how to access this cookie from another CGI script--and I'm working in Python 2.4 so a lot of the examples I've found may not apply.
  This code prints "can't get uid" followed by the rest of the page:
  c = Cookie.SimpleCookie(os.environ.get("HTTP_COOKIE"))
  print("Content-Type: text/html")
  print c.output()
  print("\n\n")
  uid = c.get("uid")
  #uid = c["uid"].value # this would create an error and page would fail totally
  if uid is None: 
      print("can't get uid")
      uid = 1 # set manually to prevent the rest of the page from failing
  
  I haven't done anything fishy with the domain the cookie applies to, so I don't understand why this doesn't grab the uid value. By the way, if I try to print c.output(), it's blank.
  
  A:
  
  Okay, I think I figured this out! I confirmed that os.environ.get("HTTP_COOKIE") was getting something, and then played with the order of the elements in my tiny test until it worked. Then I reproduced that order in my more complicated script. (Specifically: content type declaration, two newlines, get cookie, get value from cookie, everything else.)
  The main thing I've learned about Python and CGI is that the order of elements (starting with the content type declaration) is very fussy. Thanks very much for the hints in the right direction.
  
  