我正在尝试使用python 2.7和Karrigell读取上传的文件。但它告诉我:
Traceback (most recent call last):
File "C:\Karrigell-3.1.1\karrigell\core\HTTP.py", line 333, in process_request
File "C:\Karrigell-3.1.1\karrigell\core\k_target.py", line 399, in run
File "", line 7, in
File "cgi.pyc", line 541, in __getitem__
KeyError: 'filename'
这是我的web_access.py:
import cgi, os
form = cgi.FieldStorage()
fileitem=form['filename']
if fileitem.file:
print fileitem.file.read()
else:
print "Error"
我的Html页面:
<section>
Enter the text:
<form action="web_access.py" method="post" enctype="multipart/form-data">
<input type="file" name="filename" id="file" value="" size="50"/>
<br />
<input type="submit" value="Analyze"/>
</form>
</section>
请帮帮我!
答案 0 :(得分:0)
对于Karrigell,您不需要使用CGI模块;您将表单字段的引用作为内置对象REQUEST
web_access.py可能类似于
print REQUEST['filename'].file.read()
记录在案here