korakot / kora

Convenient tools for Colab
MIT License
269 stars 38 forks source link

chdir_notebook() throws KeyError #4

Closed dorukkarinca closed 3 years ago

dorukkarinca commented 3 years ago

Hey, I just did the following:

!pip install kora
from kora import drive as koradrive
koradrive.chdir_notebook()

and the last line returned the following error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/pydrive/files.py in __getitem__(self, key)
    133     try:
--> 134       return dict.__getitem__(self, key)
    135     except KeyError as e:

KeyError: 'title'

During handling of the above exception, another exception occurred:

HttpError                                 Traceback (most recent call last)
8 frames
/usr/local/lib/python3.6/dist-packages/pydrive/files.py in FetchMetadata(self, fields, fetch_all)
    236                                                  fields=fields)\
--> 237           .execute(http=self.http)
    238       except errors.HttpError as error:

/usr/local/lib/python3.6/dist-packages/googleapiclient/_helpers.py in positional_wrapper(*args, **kwargs)
    133                     logger.warning(message)
--> 134             return wrapped(*args, **kwargs)
    135 

/usr/local/lib/python3.6/dist-packages/googleapiclient/http.py in execute(self, http, num_retries)
    897         if resp.status >= 300:
--> 898             raise HttpError(resp, content, uri=self.uri)
    899         return self.postproc(resp, content)

HttpError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/1XIcp8iyVzjURLJaxdDEWJigIj_6CEi5b?alt=json returned "File not found: 1XIcp8iyVzjURLJaxdDEWJigIj_6CEi5b">

During handling of the above exception, another exception occurred:

ApiRequestError                           Traceback (most recent call last)
<ipython-input-1-a7dca346acff> in <module>()
     15   get_ipython().system('pip install face_alignment')
     16   from kora import drive as koradrive
---> 17   koradrive.chdir_notebook()
     18 
     19 import numpy as np

/usr/local/lib/python3.6/dist-packages/kora/drive.py in chdir_notebook()
     92     # then get the directory and change to it
     93     _, file_id = current_notebook()
---> 94     path = get_path(file_id)
     95     nb_dir = '/content/drive' / path.parent
     96     os.chdir(nb_dir)

/usr/local/lib/python3.6/dist-packages/kora/drive.py in get_path(file_id, drive)
     69         drive = auth_drive()
     70     f = drive.CreateFile({'id': file_id})
---> 71     name = f['title']
     72     if f['parents']:
     73       parent_id = f['parents'][0]['id']

/usr/local/lib/python3.6/dist-packages/pydrive/files.py in __getitem__(self, key)
    137         raise KeyError(e)
    138       if self.get('id'):
--> 139         self.FetchMetadata()
    140         return dict.__getitem__(self, key)
    141       else:

/usr/local/lib/python3.6/dist-packages/pydrive/auth.py in _decorated(self, *args, **kwargs)
     73       self.http = self.auth.Get_Http_Object()
     74 
---> 75     return decoratee(self, *args, **kwargs)
     76   return _decorated
     77 

/usr/local/lib/python3.6/dist-packages/pydrive/files.py in FetchMetadata(self, fields, fetch_all)
    237           .execute(http=self.http)
    238       except errors.HttpError as error:
--> 239         raise ApiRequestError(error)
    240       else:
    241         self.uploaded = True

ApiRequestError: <HttpError 404 when requesting https://www.googleapis.com/drive/v2/files/1XIcp8iyVzjURLJaxdDEWJigIj_6CEi5b?alt=json returned "File not found: 1XIcp8iyVzjURLJaxdDEWJigIj_6CEi5b">

The file in https://www.googleapis.com/drive/v2/files/1XIcp8iyVzjURLJaxdDEWJigIj_6CEi5b?alt=json appears to be a 404 according to the error but when you visit it on a browser, it returns:

{
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 }
}

Is this a bug or a temporary Google Cloud issue about usage limits?

thanakijwanavit commented 3 years ago

did you authenticate with the same account as the one used by colab?

dorukkarinca commented 3 years ago

yes. this happened after auth

dorukkarinca commented 3 years ago

just tried again and everything is fine. I think the reason was Google's free tier API was exhausted.