Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python 3, getting file not found error on absolute path

I'm trying to write a binary file i'm downloading from The Movie Database. I can successfully save the file if it's on the same folder the .py file is, but cannot save it on a location outside it even after the containing directory is created by the script and using absolute path:

FileNotFoundError: [Errno 2] No such file or directory: '/home/gabriel/Desktop/movies/w185/tt2024544.jpeg'

Pice of code:

filepath    =   os.path.join(webDir,size,imdbid + '.' + filetype);
f           =   open(filepath, "wb");

I'm puzzled. Any tips?

Thanks!

like image 577
Gabriel Avatar asked Apr 26 '26 01:04

Gabriel


1 Answers

I had the same issue and it turned out that a directory in my absolute path was not existing. One can easily check with:

import os
path = os.path.split(filepath)[0]
print('check for path', os.path.exists(path))
like image 95
Markus Dutschke Avatar answered Apr 28 '26 13:04

Markus Dutschke