Forums

No matter WHAT I do.... [Errno 2] No such file or directory

I HAVE TRIED E-V-E-R-Y-T-H-I-N-G....

I've been at this bloody problem for 2 days now...

I've tried :

  • filename.csv
  • /static/filename.csv
  • /home/static/filename.csv
  • /home/username/static/filename.csv
  • http://username.pythonanywhere.com/static/filename.csv

I reconfigured the static folder like 3 or 4 times.

I AM STILL GETTIG THAT #&^$#&^%@# error.... IT DRIVES ME NUTS !!!

Where have you been trying those? What are you trying to accomplish?

Ok. I got a solution...

The only way for me to use a csv (read info from it) is to use the path.dirname function :

ROOT = path.dirname(path.realpath(file))

then :

input_file = ROOT + "/static/" + request.form.get('filechoose')

This works now (finally!). Was really frustrating...

Is there a reason why it's so hard to access external files using pythonanywhere + flask ? Is it a security issue ?

It's not difficult. It's just that you were not paying attention to the working directory. When you're running a script and use a relative path, you've cd'ed into the directory, so the working directory is where the script is. When you run in a web app, the working directory is whatever you set it as on the web app config page.

I see. Still pretty complicated if you are used to a 'regular' server. But I'm glad we got things working...