<div class="gmail_quote">On Wed, Dec 30, 2009 at 9:56 AM, Carsten Haese <span dir="ltr"><<a href="mailto:carsten.haese@gmail.com">carsten.haese@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
So, guess again. The "trivial example" has three more lines of code. One<br>
of them is unlike any line you have in your code. That's the line<br>
responsible for producing the "Set-Cookie" header, and that's the line<br>
you're missing.<br></blockquote><div><br></div></div>So you're suggesting I somehow execute this code:<br>python Cookie_setheaders.py<br>in my script? I presume I'd change "Cookie_setheaders.py" to my file name. That doesn't make sense to me.<br>
<br>I'm sorry but I'm lost. The page on which you said had the missing line:<br><a href="http://www.doughellmann.com/PyMOTW/Cookie/index.html">http://www.doughellmann.com/PyMOTW/Cookie/index.html</a><br>has the following code:<br>
<br>import Cookie<br>c = Cookie.SimpleCookie()<br>c['mycookie'] = 'cookie_value'<br>print c<br><br>All of which is in my code. The tutorial gave this printout:<br><br>$ python Cookie_setheaders.py<br>Set-Cookie: mycookie=cookie_value<br>
<br>It also has this code:<br><br>import Cookie<br>import datetime<br><br>def show_cookie(c):<br>    print c<br>    for key, morsel in c.iteritems():<br>        print<br>        print 'key =', morsel.key<br>        print '  value =', morsel.value<br>
        print '  coded_value =', morsel.coded_value<br>        for name in morsel.keys():<br>            if morsel[name]:<br>                print '  %s = %s' % (name, morsel[name])<br><br>which, when I tried it, printed nothing at all. Not a very good tutorial :(<br>
<br>This page<br><a href="http://webpython.codepoint.net/cgi_set_the_cookie">http://webpython.codepoint.net/cgi_set_the_cookie</a><br>has the following code:<br><br>#!/usr/bin/env python<br>import time<br>print 'Set-Cookie: lastvisit=' + str(time.time());<br>
print 'Content-Type: text/html\n'<br>print '<html><body>'<br>print 'Server time is', time.asctime(time.localtime())<br>print '</body></html>'<br><br><br><br>#!/usr/bin/env python<br>
import time, Cookie<br>cookie = Cookie.SimpleCookie()<br>cookie['lastvisit'] = str(time.time())<br>print cookie<br>print 'Content-Type: text/html\n'<br>print '<html><body>'<br>print 'Server time is', time.asctime(time.localtime())<br>
print '</body></html>'<br><br>all of which is included in my code (except for extraneous print statements). Here again is my code:<br><br>#! /usr/bin/python<br><br>import string<br>import cgitb; cgitb.enable()<br>
import MySQLdb<br>import cgi<br>import sys,os<br>sys.path.append(os.getcwd())<br>from login import login<br>import datetime, Cookie, random<br>from particulars import title<br>from templateFrame import top, bottom<br>from particulars import myCookie<br>
import time<br>import fpformat<br>from sets import Set<br>from particulars import ourOptions<br><br>def cart():<br>  print '''Content-Type: text/html\r\n<br><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><br>
<html><br>'''<br>  cookie = os.environ.has_key('HTTP_COOKIE')<br>  if not cookie:<br>    cookie = Cookie.SimpleCookie()<br>    cExpires, cPath, cComment, cDomain, cMaxAge, cVersion = myCookie()<br>
    cookie['lastvisit'] = str(time.time())<br>    cookie['lastvisit']['expires'] = cExpires<br>    cookie['lastvisit']['path'] = cPath<br>    cookie['lastvisit']['comment'] = cComment<br>
    cookie['lastvisit']['domain'] = cDomain<br>    cookie['lastvisit']['max-age'] = cMaxAge<br>    cookie['lastvisit']['version'] = cVersion<br>    cookie['mycookie'] = 'mycookie'<br>
    cookieFlag = 'new'<br>  else:<br>    cookie = Cookie.SimpleCookie(cookie)<br>    cookieFlag = 'old'<br>#  Don't know what to do with this. It's for when client won't accept cookies<br>#  sessionDir = os.environ['DOCUMENT_ROOT'] + '/tmp/.session'<br>
#  session = shelve.open(sessionDir + '/sess_' + sid, writeback=True)<br>#  session['lastvisit'] = repr(time.time())<br>#  session.close()<br>  print cookieFlag<br>  cookie.load(cookie)<br>  print cookie<br>
 ...<br><br>Please advise.<br>TIA,<br>beno<br>