473,740 Members | 6,250 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cookie not reading first time though...

I'm trying to learn how to use python for cgi scripts...

I created a form that submits some info that I put in a cookie. Then
the script calls itself and reads the cookie, and displays a different
form to get more information.

The problem I'm running into is the script is setting the cookie... but
it doesn't read it the first time through for some reason, if I
immediately try it again it works fine. So for some reason it's not
picking up the cookie the first time.

Would it be a better idea to break the script into two different scripts
to accomplish this?

Any advise would be appreciated, please be gentle, I'm still a newbie

here is the script:


import cgi,os,Cookie
import cgitb; cgitb.enable()

def name_race():
print "Content-Type: text/html\n\n"
print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"
print "<html>"
print "<body>"
print "<form method = post ACTION =\"test.py\"> "
print "<table><tr >"
print "<td><b>Nam e:</b></td><td><input type=text name=\"name\"></td>
print "</table>"
print "<p>"
print "<table>"
print "<tr>"
print "<td><b>Rac e:</b></td></tr>"
print "<tr>"
print "<td>Human</td><td><input type=radio name=\"race\" value=\"1
print "<tr>"
print "<td>Elf</td><td><input type=radio name=\"race\" value=\"2\">
print "</table>"
print "<p>"
print "<input type = hidden name=\"action\" value=\"getclas s\">"
print "<input type = submit value =\"Enter\">"
def pick_class():
mycookie = Cookie.SmartCoo kie(os.environ. get("HTTP_COOKI E", ""))
race = mycookie["race"].value
name = mycookie["name"].value
print "Content-Type: text/html\n\n"
print "<html>"
print "<body>"
print name
print race
print "</body>\n</html>"

def print_sheet():
def main():
form = cgi.FieldStorag e()
mycookie = Cookie.SmartCoo kie()
if form.has_key("n ame") and form.has_key("r ace"):
if (form["action"].value == "getclass") :
mycookie["name"] = form["name"].value
mycookie["name"]["max-age"] = 60
mycookie["race"] = form["race"].value
mycookie["race"]["max-age"] = 60
print mycookie

else: name_race()

Jul 18 '05 #1
0 1096

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: N.K | last post by:
Hi , Python's existing cookie module doesnt supports new cookie headers SetCookie2 , How to submit a patch for that ? I tried emailing person who owns that module.But no response. Thanks, Nirmal
by: Michael | last post by:
I am reading and setting a cookie using JavaScript in the BODY onload and onunload events respectively. This works fine. However when I use ASP to set the cookie under some condition where I want to override the last value set in the onunload event, it has no effect. The next onload still has the old value. Any ideas? The following code simulates the problem I experience. --------------------------------------------------
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code behind and don't use a domain then I can not change or remove that cookie's value on the client. If I subsequently create the cookie again in the codebehind then I actually end up with TWO cookies with the same name in the response. The cookie...
by: Gridlock | last post by:
I'm trying to read the cookies using HttpContext.Current.Request.Cookies, but the only cookie that I get is the ASP.NET SessionId cookie. There are many cookies on the machine, why am I only getting the one cookie? Thanks, - Stew
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex http://www.developersdex.com ***
by: rn5a | last post by:
A web.config file has the following code: <configuration> <system.web> <authentication mode="Forms"> <forms name="NETConnectCookie" loginUrl="Login.aspx"> <credentials passwordFormat="SHA1"/> </forms> </authentication> </system.web>
by: Dan | last post by:
Hi, I am trying to refresh the cookie to make sure the timeout is reset by simply calling a blank page on my site. I am doing this because I have an external site hosted in my web that isn't sharing the auth mechanism. I can test this easily by simply having a hidden iframe and use a javascript call to refresh my sites blank page every time the external site loads a page and this does work fine, the cookie is refreshed as expected if...
by: Jerim79 | last post by:
I did try to find the answer to this before posting, so this isn't a knee jerk reaction. What I am trying to accomplish is to have a script that opens a cookie, reads a value, and then use a switch/case to take action based on that value in the cookie. I want to set the cookie manually, so I don't need setcookie(). I see that in PHP it stores the cookie in memory. Is there a way to have PHP just read a cookie from the desktop machine?...
by: Doogie | last post by:
Hi, I am having a problem reading a cookie that I can see is being created. I create the cookie in my global.aspx.vb page like so: Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) Dim user As String = Current.User.Identity.Name Dim roleCookieName As String = user & "-Roles" Dim rolesList As String = Response.Cookies(roleCookieName ).Value 'Only try to create the cookie if it is not already created.
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.