473,320 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to set a cookie and then redirect using Python?

I've read that Python does not alllow one to set a cookie and then redirect. I'm trying to save the current page location before pushing the user to the signin page.

I'm coming from ASP, which allows for this in a very simple manner:
Expand|Select|Wrap|Line Numbers
  1. if request.cookies("GDtoken") = '' then
  2.   response.cookies("cpage") = request.servervariables("PATH_INFO")
  3.   response.redirect "signin.asp"
  4. end if
  5.  
... I'm surprised that I couldn't find a workaround or a solution for Python.

Here's my Python code:
Expand|Select|Wrap|Line Numbers
  1. if 'GDtoken' not in cookie:
  2.   #save the location of this page to the cookie
  3.   cookie['cpage'] = os.environ.get('SCRIPT_NAME', '/')
  4.   cookie['cpage']['expires'] = 60*30
  5.   cookie['cpage']['path'] = '/'
  6.  
  7.   #save the continuation page cookie
  8.   print 'Status: 302 Moved Temporarily'
  9.   print cookie.output()
  10.  
  11.   #and redirect user to the signin page
  12.   print 'Location: signin.py'
  13.   print
  14.   exit()
  15.  
The cookie is not set when I get to signin.py
How would one do this in Python?

Thanks!
Jan 22 '11 #1
0 1716

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: dw | last post by:
I thought someone would like ASPN's python cookie book inside chm for easy offline-searching: http://miaw.compeng.org/~dody/aspncookbook.chm last crawled around 15jan04. ...
2
by: bagsmode | last post by:
Hi, I'm trying to set a session cookie and then redirect, however I get the error: Status: 302 Moved Location: /index.cgi I thought I recall getting an error like this when I first tried...
1
by: -------- | last post by:
Hello I've been looking for a small snippet of code which I haven't had much luck finding. I was wondering if anyone is aware of a script that might be able to do the following for me: On my...
2
by: Gonnasi | last post by:
I want fetching some articles from nytimes.com for my Palm, and I want a clear, simple article too, my Palm has only 8M RAM. With the WGET, I can fetching the page like:...
3
by: Peter Row | last post by:
Hi, I better get the background stuff out the way first, so here goes: - Porting a VB6 webclass app to VB.NET using HttpHandlers and FormsAuthentication - When someone visits my site...
0
by: Bill Borg | last post by:
Hello all, Not sure I can describe this adequately, but I am creating an endless loop when an authenticated user signs out. When the user signs out, I want to remove authentication, abandon...
4
by: mike.biang | last post by:
I have an ASP page that is using an XMLHTTP object to request various pages from my server. I keep a single session throughout the XMLHTTP requests by bassing the ASPSESSIONID cookie through the...
6
by: Alessandro Fachin | last post by:
Hi, i am trying to forge a new cookie by own with cookielib. But i don't still have success. This a simply code: import cookielib, urllib, urllib2 login = 'Ia am a cookie!' cookiejar =...
5
by: cbhoem | last post by:
Hi - I am trying my hand at python cookies. I'm confused about a few things though. Do the python cookies get written to a cookies text file? I have simple code below -- I see the cookie in...
0
by: Chris Rebert | last post by:
See the 'cookie' module: http://www.python.org/doc/2.5.2/lib/module-Cookie.html Also: A. In the future, Google is your friend! That page is the top hit for "python cookie" for Christ's sake;...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.