按照网络的教程用Python编写CGI上传文件,一直出现500,怎么回事?
html文件:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>文件上传</title>
</head>
<body>
<form enctype="multipart/form-data" action="save_file.py" method="post">
<p>
选中文件: <input type="file" name="filename" />
</p>
<p>
<input type="submit" value="上传"/>
</p>
</form>
</body>
</html>
.py文件
#!/usr/bin/python
# -*- coding:utf-8 -*-
import cgi, os
import cgitb; cgitb.enable()
# 获取文件名
f = cgi.FiledStorage().getvalue('filename')
# 检测文件是否上传
if f is not None:
# 设置文件路径
fn = os.path.basename(f.filename.replace("","/"))
open('/tmp/' + fn,'wb').write(f.file.read())
message = '文件 "' + fn + '" 上传成功'
else:
message = "文件没有上传"
print """
Content-Type:text/html
<html>
<head>
<meta charset="utf-8">
<title>文件上传</title>
</head>
<body>
<p> %s </p>
</body>
</html>
""" % (message,)
错误信息:
[Thu May 11 10:24:46.697197 2017] [http:error] [pid 8254] [client 127.0.0.1:58072] AH02429: Response header name '<!--' contains invalid characters, aborting request, referer: http://studycgi/file/file.html
127.0.0.1 - - [11/May/2017:10:24:41 +0800] "POST /file/save_file.py HTTP/1.1" 500 4063
你不觉得你的错误信息里面的url长的很奇怪么,在你的浏览器打开看看。
不是应该studycgi.com么
错误信息不是比较明确么: Response header name '<!--' contains invalid characters