Is it possible to use urlretrieve()
in order to download something into a subfolder without expressing it in an absolute but relative manner?
For example:
urllib.request.urlretrieve(url, '/downloads/2017/foo.txt')
Everytime I add a path to the filename python throws following error:
File "C:\Program Files\Python36\lib\urllib\request.py", line 258, in urlretrieve tfp = open(filename, 'wb') FileNotFoundError: [Errno 2] No such file or directory: '/downloads/2017/foo.txt'
But when I use this code:
urllib.request.urlretrieve(url, 'foo.txt')
it happily downloads the file.
I think I am missing something basic here, but after searching the interwebs for quite a while I haven't found an answer yet. Does anyone know how relative filepaths should be expressed in the urlretrieve()
method?