简单的python CGI cookie脚本,从表单获取数据

2024-04-19 00:35:45 发布

您现在位置:Python中文网/ 问答频道 /正文

您好,我正在尝试创建一个非常简单的pythoncgi脚本,它接受表单数据并将其放入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)

正如您所看到的,它是非常基本的,但是我收到了一个“在日志中过早结束脚本头错误”。在


Tags: textnameform脚本idemailcookiehtml
2条回答

如果我没搞错的话,看起来您打印了两次Content-type头:一次在第2行,另一次是在set\u clientCookie()运行时。在

你能发布小提琴手或萤火虫的原始输出吗?在

复制粘贴你的代码到我的服务器显示没有错误。您可以尝试删除当前不用于限制可能性的所有导入。当在命令行上运行时,它确实会发出关于SmartCookie不安全且不使用它的警告,但不会抛出错误。在

相关问题 更多 >