Forums

IOError: [Errno 2] No such file or directory

My code is giving error:

2018-07-12 16:56:04,645: [2018-07-12 16:56:04,639] ERROR in app: Exception on /file [POST]
2018-07-12 16:56:04,646: Traceback (most recent call last):
2018-07-12 16:56:04,646:   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1988, in wsgi_app
2018-07-12 16:56:04,646:     response = self.full_dispatch_request()
2018-07-12 16:56:04,646:   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1641, in full_dispatch_request
2018-07-12 16:56:04,646:     rv = self.handle_user_exception(e)
2018-07-12 16:56:04,646:   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1544, in handle_user_exception
2018-07-12 16:56:04,647:     reraise(exc_type, exc_value, tb)
2018-07-12 16:56:04,647:   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1639, in full_dispatch_request
2018-07-12 16:56:04,647:     rv = self.dispatch_request()
2018-07-12 16:56:04,647:   File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1625, in dispatch_request
2018-07-12 16:56:04,647:     return self.view_functions[rule.endpoint](**req.view_args)
2018-07-12 16:56:04,648:   File "/home/jk1997/mysite/app.py", line 60, in index
2018-07-12 16:56:04,648:     filepath=os.path.join(app.config['UPLOAD_FOLDER'], filename)
2018-07-12 16:56:04,648:   File "/usr/local/lib/python2.7/dist-packages/werkzeug/datastructures.py", line 2653, in save
2018-07-12 16:56:04,648:     dst = open(dst, 'wb')
2018-07-12 16:56:04,648: IOError: [Errno 2] No such file or directory: '/home/simmi/student.csv'
2018-07-12 16:56:04,639: Exception on /file [POST]#012Traceback (most recent call last):#012  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1988, in wsgi_app#012    response = self.full_dispatch_request()#012  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1641, in full_dispatch_request#012    rv = self.handle_user_exception(e)#012  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1544, in handle_user_exception#012    reraise(exc_type, exc_value, tb)#012  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1639, in full_dispatch_request#012    rv = self.dispatch_request()#012  File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 1625, in dispatch_request#012    return self.view_functions[rule.endpoint](**req.view_args)#012  File "/home/jk1997/mysite/app.py", line 60, in index#012    filepath=os.path.join(app.config['UPLOAD_FOLDER'], filename)#012  File "/usr/local/lib/python2.7/dist-packages/werkzeug/datastructures.py", line 2653, in save#012    dst = open(dst, 'wb')#012IOError: [Errno 2] No such file or directory: '/home/simmi/student.csv'

Tried this solution but it did not work

link to my code

[edit by admin: formatting]

Your code is trying to access the file /home/simmi/student.csv, but your username is jk1997 -- which means that your home directory is /home/jk1997.

Somewhere in your code you are defining the directory where uploaded files should go -- from the traceback, it looks like you're setting a configuration variable called UPLOAD_FOLDER. Right now that is set to something like /home/simmi/. You should set it to something in your own home directory; I'd suggest creating a directory called uploads inside your home directory and then setting it to /home/jk1997/uploads, because allowing people to upload stuff directly into your home directory could be a security problem.

I have tried the solution you are telling but it's still giving the same error. link to my modified code

Is the error exactly the same (that is, mentioning "simmi" in the error message)? If so, perhaps you didn't reload the website after making the code change?

Yup,I missed that. Sorry for such a silly mistake. Thanks a lot.