Forums

OSError: file b'filtre.csv' does not exist

Hello everybody, I'm a beginner in using pythonanywhere and I've got some problems in developing my first web app.

First of all, my webpage' structure is:

 ---/home/mentor/mysite/
    |
    ------ servidor/
                   |
                   -------- run.py
                   -------- filtre.csv
                   -------- app/
                              |
                              ---- _init_.py
                              ---- views.py
                              ---- templates/   --> html is inside this folder
                              ---- static/    ---> all the .png,... are inside this folder
                              ---- scripts/   ---->  tot.py is inside this folder

The problem apears when after filling out a form in the webpage, this action runs a function in views.py that uses tot.py functions to work. One of this functions needs to read 'filtre.csv' but this function doesn't find that file.

code inside views.py which is runed after the form is:

  from flask import render_template
  from app import app
  from flask import request
  from .scripts.tot import func
  .....
 @app.route('/tot', methods=['POST'])
       def resposta():
              f=func()
              ....

inside tot.py, func()'s code is:

   import pandas as pd
   def func():
         d=pd.read_csv('filtre.csv')
         ......

I've already tried to write pd.read_csv('/home/mentor/mysite/servidor/'), but it doesn't work. Can anybody help me?

Thank's !

PD.: something strange apears in my init.py, run.py and WSGI file: 'imported but unused'. I will write down the code of this 3 files, maybe the problem is here...

run.py file :

     # -*- coding: utf-8 -*-
     from app import app    ---> 'app' imported but unused

init.py file:

 from flask import Flask
 app = Flask(__name__)
 from app import views    ---> 'views' imported but unused

WSGI configuration file:

import sys
project_home = '/home/mentor/mysite/servidor'
if project_home not in sys.path:
        sys.path.append(project_home) #= [project_home] + sys.path

from run import app as application

I believe the "imported but unused" comment is a linter saying that that is bad style? that's fine (it is being used later when we deploy your webapp, just not used directly in the wsgi.py file)

you said you tried pd.read_csv('/home/mentor/mysite/servidor/') but did you try pd.read_csv('/home/mentor/mysite/servidor/filtre.csv')?

Hi Conrad, thank's for trying to help me! Yes, I tried pd.read_csv('/home/mentor/mysite/servidor/filtre.csv') and that was not the problem. I realised that my problem was in run.py file, I've changed the directory with os module and now it works correctly. Thank's again.