googlearchive / PyDrive

Google Drive API Python wrapper library
Other
1.31k stars 273 forks source link

Cannot pass http object to ListFile() #112

Open Lykos153 opened 7 years ago

Lykos153 commented 7 years ago

I'm trying to avoid overhead by re-using an http object for every call. The docs state that it can be used with every method which takes an param parameter. It works fine with Upload() but it doesn't with ListFile().

>>> drive.ListFile({'q': "'root' in parents and trashed=false", "http": http}).GetList()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.6/site-packages/pydrive/apiattr.py", line 162, in GetList
    for x in self:
  File "/usr/lib/python3.6/site-packages/pydrive/apiattr.py", line 146, in __next__
    result = self._GetList()
  File "/usr/lib/python3.6/site-packages/pydrive/auth.py", line 75, in _decorated
    return decoratee(self, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/pydrive/files.py", line 63, in _GetList
    self.metadata = self.auth.service.files().list(**dict(self)).execute(
  File "/usr/lib/python3.6/site-packages/googleapiclient/discovery.py", line 722, in method
    raise TypeError('Got an unexpected keyword argument "%s"' % name)
TypeError: Got an unexpected keyword argument "http"
adyanth commented 4 years ago

Facing the same issue here, any workarounds?

shcheklein commented 4 years ago

@adyanth could you please try PyDrive2 https://github.com/iterative/PyDrive2 - it's a fork that is under active development, and one of the problems we've solved already is caching HTTP connections properly (one per thread to be precise) so that we don't run out of open files, and we don't reestablish them again and again. Let me know if that works for you.

adyanth commented 4 years ago

Yeah, that seems to be okay. But after I faced that issue, I searched for other alternatives, and finally found a library fs.googledrivefs, which is a pyfilesystem2 implementation for Google Drive. Best thing about it is, it provides a file system like access vs the list files and IDs in PyDrive. One "disadvantage" would be if you need to multiple files with the same name, which is possible in PyDrive, but not in googledrivefs like any sane file system would not allow.

shcheklein commented 4 years ago

@adyanth yep, sounds cool. In case of dvc.org (that's where we use PyDrive2) we need a somewhat better control and flexibility over operations we do with a storage, so probably virtual file system library won't be enough.