| | |
Cookie Error
![]() |
•
•
Join Date: Jun 2009
Posts: 41
Reputation:
Solved Threads: 0
I have the following files:
in add.py it gives a key error at the cookie bit, why?
Python Syntax (Toggle Plain Text)
# add.py #!/usr/bin/env python import os import Cookie import hashlib import MySQLdb import cgi import cgitb; cgitb.enable() def showform(): reshtml = '''Content-Type: text/html\n <html> <body> <form action='add.py' method='post'> Name: <input type=text name=name size = 15><br> URL : <input type=text name=url size=30><br> <input type=submit value="Add"></form> </body> </html> ''' print reshtml def main(): conn = MySQLdb.connect(host="localhost", user="root", passwd="", db="test") reshtml = '''Content-Type: text/html\n <html><body> %s </body> </html> ''' cursor = conn.cursor () form = cgi.FieldStorage() name = form['name'].value url = form['url'].value cookie = Cookie.SimpleCookie() string_cookie = os.environ.get('HTTP_COOKIE') if string_cookie: user = cookie['u'].value else: user = "dad" cursor.execute("insert into bookmarks values ('%s', '%s', '%s')" % (user, name, url)) print reshtml % ("") form = cgi.FieldStorage() if not form.has_key('url'): showform() else: main()
Python Syntax (Toggle Plain Text)
#!/usr/bin/env python import os import Cookie import hashlib import MySQLdb import cgi import cgitb; cgitb.enable() def showform(): reshtml = '''Content-Type: text/html\n <html> <body> <a href="register.py">Not a member? </a> <form action='login.py' method="post"> Username: <input type=text name=person value="New User" size = 15><br> Password: <input type=password name=pass value="" size=15><br> <input type=submit value="Login"></form> </body> </html> ''' print reshtml def main(): conn = MySQLdb.connect(host="localhost", user="root", passwd="", db="test") reshtml = '''Content-Type: text/html\n <html><body> %s </body> </html> ''' cursor = conn.cursor () form = cgi.FieldStorage() who = form['person'].value passw = form['pass'].value m = hashlib.md5() m.update(passw) cursor.execute("select * from pass where user='%s' and passwrd='%s'" % (who, m.digest())) if cursor.rowcount != 1: print reshtml % ("Invalid username or password") else: cookie = Cookie.SimpleCookie() string_cookie = os.environ.get('HTTP_COOKIE') if not string_cookie: cookie['u'] = who else: cookie['u'] = who print cookie cursor.execute("select name, url from bookmarks where user='%s'" % (who)) ro = cursor.fetchall() st = [] for row in ro: st.append([row[0], row[1]]) blah = "<a href='add.py'>add bookmark</a>\n" for s in st: for a in s: blah += a + "\t\t" blah += "\n" print reshtml % (blah) form = cgi.FieldStorage() if not form.has_key('person'): showform() else: main()
![]() |
Similar Threads
- Cookie serialize error (PHP)
- session variable error (PHP)
- Page cannot be found server dns error (Viruses, Spyware and other Nasties)
- errors in phpbb (PHP)
- IE Syntax Error and Can“t browse some sites (Viruses, Spyware and other Nasties)
- Rundll Error (Viruses, Spyware and other Nasties)
- Compilation Error Handles cmdLogin.ServerClick (ASP.NET)
- need help, new to this lots of bad things (Viruses, Spyware and other Nasties)
- Inserting array into cookie (PHP)
- XP error message "Send, don't send" (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: python browser?
- Next Thread: Rounding numbers
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment avogadro backend beginner binary book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary dynamic examples exe file float format function gnu graphics gui heads homework import inches input java launcher library line lines linux list lists loop mouse mysql mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame pysimplewizard python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib






