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 4273090
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:39:57+00:00 2026-05-21T07:39:57+00:00

I am familiar with assigning, creating cookies in Python. But I am unsure how

  • 0

I am familiar with assigning, creating cookies in Python. But I am unsure how to create a cookie that will last until the current browser session is closed(so I have a very rudimentary way of telling when the user is returning to my website).

So which cookie header do I set to make sure the cookie will expire/delete when the browser is closed in Python? Do I use the SimpleCookie object or another object for this?

This thread says I set the cookie_lifetime flag/header in PHP, but what about for python? http://bytes.com/topic/php/answers/595383-how-declare-cookie-will-destroy-after-browser-closed

Would this create a cookie that expires on closing of the browser?

cookie  = Cookie.SimpleCookie()
cookie["test"] = "MYTEST"
cookie["test"]['expires'] = 0 # or shd I set the max-age header instead?
print str(cookie) + "; httponly"
  • 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. Editorial Team
    Editorial Team
    2026-05-21T07:39:58+00:00Added an answer on May 21, 2026 at 7:39 am

    Just leave out the "expires" value altogether, i.e. don’t set it to anything. See the Wikipedia entry for details:

    Set-Cookie: made_write_conn=1295214458; path=/; domain=.foo.com

    […]

    The second cookie made_write_conn does not have expiration date, making it a session cookie. It will be deleted after the user closes his/her browser

    In Python:

    In [11]: from Cookie import SimpleCookie
    
    In [12]: c = SimpleCookie()
    
    In [13]: c['test'] = 'MYTEST'
    
    In [14]: print c
    Set-Cookie: test=MYTEST
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That sounds familiar I'm sure, but it's not a CSS hack issue. I'm literally
Anyone familiar with the emulator will know that during the loading phase the 'screen'
Anyone familiar with specific security issues in the current version of DotNetNuke? (I've already
I'm familiar with using a function to determine a specific condition using xtemplate but
Familiar with creating textfields in a form like this example:- Name :<input type=text name=visitor
Im familiar with accessing parent windows like this: window.parent.document.getElementById(ad_nr) But what if I want
I'm familiar with aspnet_regsql.exe to create a membership database (it produces 11 tables) However,
I am not very familiar with the OAuth flow and/or encoding, but I've managed
I am pretty familiar with jquery, but a novice at php, so excuse me
I am already familiar with creating files and putting them in user.home. I'm on

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.