2011-01-28 49 views
0

大家好,我正在嘗試創建一個非常簡單的python CGI腳本,它接受表單數據並將其放入COOKIE中。這是我的代碼。簡單的python CGI cookie腳本,從表單獲取數據

#!/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) 

正如你可以看到它是非常基本的,但我收到在日誌中「腳本頭錯誤過早結束。

回答

2

如果我沒有記錯的話,它看起來像要打印出Content-type頭兩次:一次是在第2行,並再次當set_clientCookie()運行

您能夠發佈從菲德勒或Firebug的原始輸出的也許

0

複製 - 粘貼代碼到。?我的服務器顯示沒有錯誤,你可以嘗試刪除所有你不需要的輸入正常使用來限制可能性。在命令行上運行時,它會給出關於SmartCookie不安全並且不使用它的警告,但不會引發錯誤。