Backslashes being added into my cookie in Python
<p>Hey,
I am working with Python's SimpleCookie and I ran into this problem and I am not sure if it is something with my syntax or what.  Also, this is classwork for my Python class so it is meant to teach about Python so this is far from the way I would do this in the real world.  </p>

<p>Anyway, so basically I am keeping information input into a form in a cookie.  I am attempting to append to the previous cookie with the new information entered.  But for some reason on the third entry of data the cookie suddenly gets "\" in it.  I am not sure where they are coming from though.  </p>

<p>This is the type of output I am getting:</p>

<blockquote>
  <p>"\"\\"\\\\"test:more\\\\":rttre\\":more\":and more"</p>
</blockquote>

<pre><code>#!/usr/local/bin/python

import cgi,os,time,Cookie
#error checking
import cgitb
cgitb.enable()

if 'HTTP_COOKIE' in os.environ:
    cookies = os.environ['HTTP_COOKIE']
    cookies = cookies.split('; ')
    for myCookie in cookies:
     myCookie = myCookie.split('=')
     name = myCookie[0]
     value = myCookie[1]
     if name == 'critter' :
      hideMe = value

#import critterClass

#get info from form
form = cgi.FieldStorage()
critterName = form.getvalue('input')
input2 = form.getvalue('input2')
hiddenCookie = form.getvalue('hiddenCookie')
hiddenVar = form.getvalue('hiddenVar')

#make cookie
cookie = Cookie.SimpleCookie()

#set critter Cookie
if critterName is not None:
    cookie['critter'] = critterName
#If already named
else:
    #if action asked, append cookie
    if input2 is not None:
     cookie['critter'] = hideMe+":"+input2
    else:
     cookie['critter'] = "default"

print cookie


print "Content-type: text/html\n\n"



if ((critterName is None) and (input2 is None)):
    print """
    &lt;form name="critter" id="critter" method="post" action="critter.py"&gt;
    &lt;label for="name"&gt;Name your pet: &lt;input type="text" name="input" id="input" /&gt;&lt;/label&gt;
    &lt;input type="submit" name="submit" id="submit" value="Submit" /&gt;
    &lt;/form&gt;
    """
else:
    formTwo ="""
    &lt;form name="critter2" id="critter2" method="post" action="critter.py"&gt;
    &lt;label for="name"&gt;%s wants to: &lt;input type="text" name="input2" id="input2" /&gt;&lt;/label&gt;
    &lt;input type="hidden" name="hiddenVar" id="hiddenVar" value="%s" /&gt;
    &lt;input type="submit" name="submit" id="submit" value="Submit" /&gt;
    &lt;/form&gt;
    [name,play,feed,mood,levels,end]
    """
    print formTwo % (critterName,critterName)

if 'HTTP_COOKIE' in os.environ:
    cookies = os.environ['HTTP_COOKIE']
    cookies = cookies.split('; ')
    for myCookie in cookies:
     myCookie = myCookie.split('=')
     name = myCookie[0]
     value = myCookie[1]
     if name == 'critter' :
      print "name"+name
      print "value"+value
</code></pre>
