您的位置:首頁技術文章
文章詳情頁

【Python上傳文件問題】按照網上的教程上傳文件,一直出現500錯誤

瀏覽:66日期:2022-07-20 15:16:37

問題描述

按照網絡的教程用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, osimport 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.html127.0.0.1 - - [11/May/2017:10:24:41 +0800] 'POST /file/save_file.py HTTP/1.1' 500 4063

問題解答

回答1:

你不覺得你的錯誤信息里面的url長的很奇怪么,在你的瀏覽器打開看看。

不是應該studycgi.com么

回答2:

錯誤信息不是比較明確么: Response header name ’<!--’ contains invalid characters

標簽: Python 編程
国产综合久久一区二区三区