依照網路的教學用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 '