<div class="gmail_quote">On Tue, Dec 15, 2009 at 4:01 PM, Grant Edwards <span dir="ltr"><invalid@invalid.invalid></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;">
> On Tue, Dec 15, 2009 at 2:36 PM, MRAB <<a href="mailto:python@mrabarnett.plus.com">python@mrabarnett.plus.com</a><br>
> <mailto:<a href="mailto:python@mrabarnett.plus.com">python@mrabarnett.plus.com</a>>> wrote:<br>
><br>
>     You've just created a cookie, but are trying to get a value without<br>
>     having set it first!<br>
><br>
><br>
> LOL! Rewrote code thus:<br>
><br>
>   cookie = os.environ.get('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>
<br>
cookie['lastvisit'] is a string.<br>
<br>
>     cookie['lastvisit']['expires'] = cExpires<br>
<br>
Here you're using the string 'expires' as an index into the<br>
string returned by str(time.time()).  You can only index into<br>
strings using integers.<br>
<br>
What do you expect the following statement to do?<br>
<br>
    '1260910829.18'['expires'] = <whatever><br>
<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>
>     cookieFlag = 'new'<br>
>   else:<br>
>     cookieFlag = 'old'<br>
>     print cookie['lastvisit']['expires'].value<br>
><br>
> Got this error:<br>
><br>
>  /var/www/html/<a href="http://angrynates.com/cart/cart.py" target="_blank">angrynates.com/cart/cart.py</a><br>
> <<a href="http://angrynates.com/cart/cart.py" target="_blank">http://angrynates.com/cart/cart.py</a>><br>
>   191 </html><br>
>   192 '''<br>
>   193<br>
>   194 cart()<br>
>   195<br>
> cart = <function cart><br>
>  /var/www/html/<a href="http://angrynates.com/cart/cart.py" target="_blank">angrynates.com/cart/cart.py</a><br>
> <<a href="http://angrynates.com/cart/cart.py" target="_blank">http://angrynates.com/cart/cart.py</a>> in cart()<br>
>    31   else:<br>
>    32     cookieFlag = 'old'<br>
>    33     print cookie['lastvisit']['expires'].value<br>
>    34 #  Don't know what to do with this. It's for when client won't<br>
> accept cookies<br>
>    35 #  sessionDir = os.environ['DOCUMENT_ROOT'] + '/tmp/.session'<br>
> cookie = 'lastvisit=1260898013.65; lastvisit=1260898315.01', ].value<br>
> undefined<br>
><br>
> TypeError: string indices must be integers<br>
>       args = ('string indices must be integers',)<br>
<br>
You took the string returned by str(time.time()) and tried to<br>
use 'expires' as an index into that time string.  You can't use<br>
a string to index into a string.  You can only use integers.<br>
That's what is mean't by the error message:<br>
<br>
    TypeError: string indices must be integers<br></blockquote><div><br>Thank you.<br>V<br></div></div>