Forums

IOError: [Errno 2] No such file or directory: ... for a csv file

Hello,

I am releasing a new version of my Flask site where I create a map of london using a csv of coordinates. The csv is in a subdirectory but despite the file being in the subdirectory I get:

2015-08-30 18:59:39,284 :Traceback (most recent call last):
2015-08-30 18:59:39,285 :  File "/bin/user_wsgi_wrapper.py", line 134, in __call__
2015-08-30 18:59:39,285 :    self.error_log_file.logger.exception("Error running WSGI application")
2015-08-30 18:59:39,285 :  File "/usr/lib/python2.7/logging/__init__.py", line 1185, in exception
2015-08-30 18:59:39,285 :    self.error(msg, *args, **kwargs)
2015-08-30 18:59:39,286 :  File "/usr/lib/python2.7/logging/__init__.py", line 1178, in error
2015-08-30 18:59:39,286 :    self._log(ERROR, msg, args, **kwargs)
2015-08-30 18:59:39,286 :  File "/usr/lib/python2.7/logging/__init__.py", line 1270, in _log
2015-08-30 18:59:39,286 :    record = self.makeRecord(self.name, level, fn, lno, msg, args, exc_info, func, extra)
2015-08-30 18:59:39,287 :  File "/usr/lib/python2.7/logging/__init__.py", line 1244, in makeRecord
2015-08-30 18:59:39,287 :    rv = LogRecord(name, level, fn, lno, msg, args, exc_info, func)
2015-08-30 18:59:39,287 :  File "/usr/lib/python2.7/logging/__init__.py", line 284, in __init__
2015-08-30 18:59:39,287 :    self.threadName = threading.current_thread().name
2015-08-30 18:59:39,288 :  File "/usr/lib/python2.7/threading.py", line 1160, in currentThread
2015-08-30 18:59:39,288 :    return _active[_get_ident()]
2015-08-30 18:59:39,288 :  File "/bin/user_wsgi_wrapper.py", line 126, in __call__
2015-08-30 18:59:39,288 :    app_iterator = self.app(environ, start_response)
2015-08-30 18:59:39,288 :  File "/bin/user_wsgi_wrapper.py", line 140, in import_error_application
2015-08-30 18:59:39,288 :    raise e
2015-08-30 18:59:39,289 :IOError: [Errno 2] No such file or directory: 'static/londonpostcodes.csv'

The csv file is called from the london_postcodes.py module on with open('static/londonpostcodes.csv') as f:

I am unsure if this is a csv module problem or other, but the file is definitely there. In case any member of the staff can help, you have permission to go look at my files.

Use the full path to the file, so /home/yourusername/mydirectory/myfile.csv instead of just mydirectory/myfile.csv.

Thank you, it solved the problem. Did not know i had to reference to full path. Good learning for the rest of the users as well.

> Good learning for the rest of the users as well

It's a question that comes up all the time actually, we just haven't found a way of making the answer more discoverable yet...

[Errno 2] No such file or directory: u'/home/digitalmarking/mysite/hello/static/output.csv' I am trying to create a csv file from the script that i calling from a view method with w+ mode i also trying and absolute path like this

open(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static/output.csv'),'w+')

to create my file butt shows error above i mentioned. any kind of help will be thank full.

[edit by admin: formatting]

Where are you seeing that error? I can see it's appearing in your website's error log, but that is happening when you're trying to read the file, not when you're writing to it.

@giles thanks for considering my post. sorry for my poor english

Dear: workflow: from my view.py a method like generatecsv() that calls my specific script (in this script i am writing a .csv file with a path i posted above) after my specific script ends i am trying to read this file from the location i used for writing it to make it downloadable in the same generatecsv() method problem: i checkout the log file my script is running successfully and generating data for csv file but not written to the file(i know myfile does not exit on server but it should create it according to python docs) on a path i am providing above(hence my code works accurately on my local machine and create a file if it does not exist ) in the same method when i tried to read data it shows me the error in my browser [Errno 2] No such file or directory: u'/home/digitalmarking/mysite/hello/static/output.csv' Means the problem is not when i am reding butt when i am writing it not create file if not exist:

i tries to write my csv file under different directories but it always shows the same error path. it there something with my config issues?

Can I take a look at your files? We can see them from our admin interface, but we always ask for permission first.

yes why not :)

for quick findings.

in my script first_pdf_reading_50.py line # 242 i am trying to write a csv file which i call from my view method downloadresult() line # 79 . and in my view method downloadresult() line # 80 i am trying to read this file to make downloadable to my user requests. you may also notice that i am also writing a image file on line # 70 in the same method without any error. if you want more information then ask me. :)

That's really strange! I can't see anything obviously wrong that would cause that. Is there a way I could interact with your site to trigger the bug? I see it only happens when stuff is POSTed to the view. If you don't want to make the way to reproduce the error public, just send us instructions using the "Send feedback" link above.

thanks to giles and pythonanywhere staff i have sent the exception workflow in feed back please check it.

@ giles is there i should remove the current app and again create it can it may produce some different results?

Just a follow-up note to say that we worked out what the problem was with this one over email.