KeyError: 'filename' while linking python and html using karrigell
Question: I'm trying to read an uploaded file using python 2.7 and Karrigell. But it is
showing me:

    
    
    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'
    

Here is my web_access.py:

    
    
    import cgi, os
    
    form = cgi.FieldStorage()
    fileitem=form['filename']
    if fileitem.file:
        print fileitem.file.read()
    
    else:
        print "Error"
    

My Html page:

    
    
    <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>
    

Help me out please!


Answer: With Karrigell you don't need to use the CGI module ; you get a reference to
form fields as keys of the built-in object `REQUEST`

web_access.py could be something like

    
    
    print REQUEST['filename'].file.read()
    

This is documented
[here](http://karrigell.sourceforge.net/en/fileuploads.html)

