I tried to download file yesterday and it worked. the same code is showing error today !!
basically, i am using this:
from google.colab import files
files.download('amit.txt')
MessageError: TypeError: Failed to fetch
Do you see an error dialog along the lines of https://github.com/googlecolab/colabtools/issues/17 when loading?
If not, are there any errors in the Chrome console?
no lines of #17 when loading.
i think there is no problem with chrome console, because i also tried with other browsers but same error occurs.

I have a similar problem just trying to run the the below snippet in the I/O example notebook.
from google.colab import files
with open('example.txt', 'w') as f:
f.write('some content')
files.download('example.txt')
My traceback follows:
MessageError Traceback (most recent call last)
<ipython-input-1-5cc1045d66cc> in <module>()
4 f.write('some content')
5
----> 6 files.download('example.txt')
/usr/local/lib/python3.6/dist-packages/google/colab/files.py in download(filename)
170 'port': port,
171 'path': os.path.abspath(filename),
--> 172 'name': os.path.basename(filename),
173 })
/usr/local/lib/python3.6/dist-packages/google/colab/output/_js.py in eval_js(script, ignore_result)
37 if ignore_result:
38 return
---> 39 return _message.read_reply_from_input(request_id)
40
41
/usr/local/lib/python3.6/dist-packages/google/colab/_message.py in read_reply_from_input(message_id, timeout_sec)
84 reply.get('colab_msg_id') == message_id):
85 if 'error' in reply:
---> 86 raise MessageError(reply['error'])
87 return reply.get('data', None)
88
MessageError: TypeError: NetworkError when attempting to fetch resource.
@johndeppe does this repro consistently? If you open the chrome javascript console, do you see any related error messages?
Yes. However, I am using Firefox 59.0.1 (64-bit) on Ubuntu. There's a small whack of errors in the console but none of them are immediately identifiable to me as related.
Tried in chrome and worked fine, so... /shruggie
I'm also experiencing @johndeppe's issue on macOS (same Firefox version).
I'm also having the same problem on Safari 11.0.3 & MacOS 10.13.13:
I am trying to run this code snippet:

Traceback:
`---------------------------------------------------------------------------
MessageError Traceback (most recent call last)
6 ana_data.to_csv('ana_treated.csv')
7 get_ipython().system('ls')
----> 8 files.download('ana_treated.csv')
9
10
/usr/local/lib/python3.6/dist-packages/google/colab/files.py in download(filename)
170 'port': port,
171 'path': os.path.abspath(filename),
--> 172 'name': os.path.basename(filename),
173 })
/usr/local/lib/python3.6/dist-packages/google/colab/output/_js.py in eval_js(script, ignore_result)
37 if ignore_result:
38 return
---> 39 return _message.read_reply_from_input(request_id)
40
41
/usr/local/lib/python3.6/dist-packages/google/colab/_message.py in read_reply_from_input(message_id, timeout_sec)
84 reply.get('colab_msg_id') == message_id):
85 if 'error' in reply:
---> 86 raise MessageError(reply['error'])
87 return reply.get('data', None)
88
MessageError: TypeError: Type error`
And the console displays the following error:

On firefox 59.0 it is as @johndeppe described. No console errors in firefox.
Edit: It's working perfectly in Chrome 65.0.3325.181
files.download("my_model.h5")
Following error :: any solutions?
Exception happened during processing of request from ('::ffff:127.0.0.1', 59088, 0, 0)
Traceback (most recent call last):
File "/usr/lib/python3.6/socketserver.py", line 317, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python3.6/socketserver.py", line 348, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python3.6/socketserver.py", line 361, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python3.6/socketserver.py", line 696, in __init__
self.handle()
File "/usr/lib/python3.6/http/server.py", line 418, in handle
self.handle_one_request()
File "/usr/lib/python3.6/http/server.py", line 406, in handle_one_request
method()
File "/usr/lib/python3.6/http/server.py", line 639, in do_GET
self.copyfile(f, self.wfile)
File "/usr/lib/python3.6/http/server.py", line 800, in copyfile
shutil.copyfileobj(source, outputfile)
File "/usr/lib/python3.6/shutil.py", line 82, in copyfileobj
fdst.write(buf)
File "/usr/lib/python3.6/socketserver.py", line 775, in write
self._sock.sendall(b)
MessageError Traceback (most recent call last)
----> 1 downloaded = files.download("my_model_animal.h5")
/usr/local/lib/python3.6/dist-packages/google/colab/files.py in download(filename)
170 'port': port,
171 'path': os.path.abspath(filename),
--> 172 'name': os.path.basename(filename),
173 })
/usr/local/lib/python3.6/dist-packages/google/colab/output/_js.py in eval_js(script, ignore_result)
37 if ignore_result:
38 return
---> 39 return _message.read_reply_from_input(request_id)
40
41
/usr/local/lib/python3.6/dist-packages/google/colab/_message.py in read_reply_from_input(message_id, timeout_sec)
84 reply.get('colab_msg_id') == message_id):
85 if 'error' in reply:
---> 86 raise MessageError(reply['error'])
87 return reply.get('data', None)
88
MessageError: Error: Failed to download
I had the exact same problem in Safari (11.0.3). Works fine with Chrome though.
You can try to zip the file and directly download it by using
import zipfile
path_to_zip_file = '/content/data (1).zip'
directory_to_extract_to=''
zip_ref = zipfile.ZipFile(path_to_zip_file,"r")
zip_ref.extractall(directory_to_extract_to)
zip_ref.close()
than download the file using 馃憥
from google.colab import files
files.download("")
OR
try the below code which worked for me
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
uploaded = drive.CreateFile({'title': 'my_model_animal.h5'})
uploaded.SetContentFile('my_model_animal.h5')
uploaded.Upload()
print('Uploaded file with ID {}'.format(uploaded.get('id')))
For me, the issue created by browser add-ons and disabling add-ons works for me in chrome. Firefox does not work for me.
I'm having the same problem with Safari (11.0.3) too
This requires Safari 11.1 or higher.
I am unable to download files from google collaboratory
I tried this
from google.colab import files
files.download('/content/submission_test.csv')
the cell is executing but the file is not getting downloaded.
and there is no error at all
when I uploaded that file to my drive I still wasen't able to download it
chrome throwing error Failed-Forbidden
I am not sure why this error is there. Please help i am stuck
@justdoGIT If you are using Firefox then there is an unusual solution that I use to download the files. Just print something in the current cell you are trying to download the file and then replace the print statement with the files.download('filename') code.
Don't know why this works, but works for me.
In Chrome, I realised that pop ups were getting blocked in the website. I unblocked them and now it works fine!
I encountered the same issue and tried the suggestion here:
https://stackoverflow.com/questions/53581023/google-colab-file-download-failed-to-fetch-error
for me, I need to download pkl and json file I save in /content/. I used
files.download('/content/my-file.pkl')
The weird thing is that it sometimes works and sometimes doesn't.
Does downloading using the file browser work more reliably?
@blois It does. I even put a time.sleep(20) before the line to give colab some time
Faced the same issue in downloading csv from colab in Firefox.
Here is a quick workaround (worked for me every time and its wierd):-
suppose I have saved a csv like this -
from google.colab import files
submission.to_csv('./submission.csv', sep = ',', index = False)
To download this i first do-
try downloading some file which doesnt even exist so that colab gives error
files.download('submission111111.csv')
then run
files.download('submission.csv')
which is the actual file to download.
It works everytime for me and I cant stop laughing to be able to find this wierd trick.
Most helpful comment
@justdoGIT If you are using Firefox then there is an unusual solution that I use to download the files. Just print something in the current cell you are trying to download the file and then replace the print statement with the files.download('filename') code.
Don't know why this works, but works for me.