简体   繁体   中英

Simple python CGI cookie script, get's data from form

Hello all I am trying to create a very simple python CGI script that takes form data and puts it in a COOKIE. Here is my code.

#!/usr/bin/python
print "Content-type: text/html"
print 

import Cookie, cgi, os, cgitb, smtplib, sys
cgitb.enable()

form = cgi.FieldStorage()

ID = form.getvalue('ID')
name = form.getvalue('name')
telephone = form.getvalue('telephone')
email = form.getvalue('email')
manager = form.getvalue('manager')



def set_clientCookie(ID, name, telephone, email, manager):
 #create object
 myCookie = Cookie.SmartCookie()

 #Assign value
 myCookie['ID'] = ID
 myCookie['Name'] = name
 myCookie['Tele'] = telephone
 myCookie['Email'] = email
 myCookie['Manager'] = manager

 #Send back to client
 print "Content-type: text/html"
 print
 print myCookie, "\n\n"

set_clientCookie(ID, name, telephone, email, manager)

As you can see it is very basic, but I am receiving a "Premature end of script headers error in the logs.

If I'm not mistaken, it looks like you're printing out the Content-type header twice: once on line 2, and again when set_clientCookie() is run.

Are you able to post the raw output from Fiddler or Firebug maybe?

Copy-pasting your code onto my server shows no errors. You might try to remove all imports you don't currently use to limit the possibilities. When run on the command line it does give a warning about SmartCookie being insecure and not to use it, but no errors are thrown.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM