Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 162651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:25:44+00:00 2026-05-11T11:25:44+00:00

I am working with Python’s SimpleCookie and I ran into this problem and I

  • 0

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.

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.

This is the type of output I am getting:

‘\’\\’\\\\’test:more\\\\’:rttre\\’:more\’:and more’

#!/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 '''     <form name='critter' id='critter' method='post' action='critter.py'>     <label for='name'>Name your pet: <input type='text' name='input' id='input' /></label>     <input type='submit' name='submit' id='submit' value='Submit' />     </form>     ''' else:     formTwo ='''     <form name='critter2' id='critter2' method='post' action='critter.py'>     <label for='name'>%s wants to: <input type='text' name='input2' id='input2' /></label>     <input type='hidden' name='hiddenVar' id='hiddenVar' value='%s' />     <input type='submit' name='submit' id='submit' value='Submit' />     </form>     [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 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:25:45+00:00Added an answer on May 11, 2026 at 11:25 am

    As explained by others, the backslashes are escaping double quote characters you insert into the cookie value. The (hidden) mechanism in action here is the SimpleCookie class. The BaseCookie.output() method returns a string representation suitable to be sent as HTTP headers. It will insert escape characters (backslashes) before double quote characters and before backslash characters.

    The

    print cookie 

    statement activates BaseCookie.output().

    On each trip your string makes through the cookie’s output() method, backslashes are multiplied (starting with the 1st pair of quotes).

    >>> c1=Cookie.SimpleCookie() >>> c1['name']='A:0' >>> print c1 Set-Cookie: name='A:0' >>> c1['name']=r''A:0'' >>> print c1 Set-Cookie: name='\'A:0\'' >>> c1['name']=r''\'A:0\''' >>> print c1 Set-Cookie: name='\'\\\'A:0\\\'\'' >>>  
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.