Alexandre2R
Alexandre2R

Reputation: 323

Upload local files using Google Colab

Trying to upload local files using Google Collaboratory this way:

from google.colab import files
uploaded = files.upload()

I get the following error:

Upload widget is only available when the cell has been executed in the current browser session. Please rerun this cell to enable.

I rerun the cell but it doesn't work...

Upvotes: 32

Views: 61507

Answers (6)

kavya sree
kavya sree

Reputation: 53

If you are using Chrome try this:

  1. Go to chrome://settings/content/cookies
  2. Turn off-> Block third-party cookies

This one worked for me

Upvotes: 1

ihojmanb
ihojmanb

Reputation: 482

I Gave a similar answer here, but will copy it here anyway, just because this question has reached far more users and could help far more people:

I was having the same problem a minute ago and, although I was not able to catch the error, there is an alternative to the file uploading method you are using.

You can just upload your file in Colab by clicking the folder icon at the notebook's sidebar and then clicking the upload button.

To load your file into a cell, for example a csv file, you can just write (if you are using pandas):

df = pd.read_csv('path_to/my_file.csv')

this should be browser agnostic.

Upvotes: 2

Guido
Guido

Reputation: 6722

You can whitelist the following cookies in Chrome:

https://[*.]googleusercontent.com:443

Upvotes: 13

Roei Bahumi
Roei Bahumi

Reputation: 3673

I just had the same issue, so I restarted the Kernel and refreshed the page and the issue was gone. Hope that helps.

Upvotes: 2

hynekcer
hynekcer

Reputation: 15548

That text after upload button is very universal:

[ Choose Files ]   Upload widget is only available when the cell has been executed in the current browser session. Please rerun this cell to enable.

It is a text prepared for the case that you or other person will open the shared notebook from a browser in another computer or window. It remains displayed also if the upload widget is blocked due to some security or privacy protection. A significant error message box have been usually displayed before.

If you have run the cell recently from the same window then it is useless to rerun it if no setting have been fixed between.

tl;dr) File upload requires to enable third party cookies in Chrome (the answer above - Chrome settings / Conntent settings / Block third-party cookies and site data - uncheck). In Firefox is no solution known currently.


Chrome or new Firefox
If you have disabled third-party cookies you have seen this message box (It was displayed only once when any first output cell was displayed for the first time in the notebook, maybe at startup):

Error
Could not access the resources needed to display output.
This is probably because third-party cookies are not allowed by your browser.

  Details... [ V unfold to see details ]

   These details are similar:

Chrome: NotSupportedError: Failed to register a ServiceWorker: The user denied permission to use Service Worker
Firefox: SecurityError: The operation is insecure.

They expect that you remember it when you see much later a traceback with this internal error message. The traceback with MessageError is everytimes the same because it contains a copied error that come through pipe from javascript.

Chrome: MessageError: TypeError: Cannot read property '_uploadFiles' of undefined
Firefox: MessageError: TypeError: google.colab._files is undefined

 
Old Firefox 52 ESR (Extended Support Release - still with new security updates)
Colab site never reports currently an intelligible message box for humans in an old Firefox, only a traceback.


Colaboratory work relative acceptably also with disabled third-party cookies. I was in a temptation to ignore a message at start of notebook to prefer a standard privacy. I promise that I will never disable them if I want to easily upload a file or to cooperate together with someone other or dislike a wheel icon that remains sometimes rotating busy endless while nothing is running actually :-)

Upvotes: 3

blois
blois

Reputation: 1526

It sounds like third-party cookies may be disabled in your browser, see https://github.com/googlecolab/colabtools/issues/17.

The setting is under chrome://settings/content/cookies.

Upvotes: 34

Related Questions