Open a text file on a python web application using flask


I have a Python application which analyse text data, having purpose to find the topics of the text.

What I need to to do is to make this application a web application.

I set apache, mod_wsgi and flask framework together and I correctly make a simple application which show that everything works.

But when I try to call open() function, I get Internal Server Error. I am sure that the path is correct. I try it on a standalone application and there wasn't any problem.

Do you have any clues about what's wrong?

Edit: The code that Im trying right now has nothing to do with my application.

This is the main flask file


    from flask import Flask,request,render_template

    import T_testing

    app = Flask(__name__)

    @app.route('/pref',methods = ['GET','POST'])  
    def pref():
        error = None
        return render_template('layout.html',error = error)

    @app.route('/running', methods = ['GET','POST'])
    def running ():
      error = None

      if request.method == 'POST':  
        dat = request.form['dat']
        alg = request.form['alg']
        dist = request.form['dist']
        threshold = request.form['threshold']
        numoc = request.form['numoc']

        string = T_testing.run_function(dat,alg,dist,threshold,numoc)
        return string

    if __name__ == '__main__':
        app.config['TRAP_BAD_REQUEST_ERRORS'] = True'',port=5000,debug=True)

And this is the

def run_function(st1,st2,st3,st4,st5):
        f = open('/home/christos/public/apps/flaskt/txt_files/textdata.txt','r')
        tablist = [st1,st2,st3,st4,st5]
        strlist = []
        for i in range( 0,len(tablist),1):
        return "Choises ARE: "+strlist[0]+" AND "+strlist[1]+" AND "+strlist[2]+" AND "+strlist[3]+" AND "+strlist[4]+" !!!!"

(Don't judge the code, I'm just testing..) As you can see I get some preferences from layout.html but right now I just print them.

Without the 2 lines about open() and close() in T_testing, there is no problem. I use Ubuntu by the way. And as I said the path is working on a standalone python application.

Edit: Ok, so I didn't have any solution to my problem. Does anyone had use open() function in a flask web application? I want to know if I should continue to try or to find another way to make my web application..

Edit: I tried also to create a new file with open('file-name.txt','w'), to check if the path was wrong but again I get error...

1/17/2014 4:00:08 PM

Try copying your textdata.txt file to the /tmp directory, confirm it has global read permissions, then change your open path:

  f = open('/tmp/textdata.txt','r')

If that succeeds, then you've probably got a permissions problem somewhere in your original path.

1/17/2014 4:30:32 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow