nithinmurali / pygsheets

Google Sheets Python API v4

Home Page:https://pygsheets.readthedocs.io/en/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Create in folder error

farabolaza opened this issue · comments

Error when creating a spreadsheet in folder (either by id or name)
Have used this feature in the past, but now I can't get it to work. If I omit folder destination info everything work as expected.
May be some change made by google in their dirve API that's causing this not to work.

To Reproduce
Steps to reproduce the behavior:

myspsheet = gc.create(title='sometitle',folder='1w-1TkvKzjmurc-ofpdb9z77SnUHB-GDy')
 
# or
myspsheet = gc.create(title='sometitle',folder_name='my_existing_folder_name')

# the error I get

~\Anaconda3\lib\site-packages\pygsheets\client.py in create(self, title, template, folder, folder_name, **kwargs)
    122         if folder:
    123             self.drive.move_file(result['spreadsheetId'],
--> 124                                  old_folder=self.drive.spreadsheet_metadata(fid=result['spreadsheetId'])[0].get('parents', [None])[0],
    125                                  new_folder=folder)
    126         return self.spreadsheet_cls(self, jsonsheet=result)

~\Anaconda3\lib\site-packages\pygsheets\drive.py in spreadsheet_metadata(self, query, only_team_drive, fid)
    144         """
    145         if fid:
--> 146             return self._execute_request(self.service.files().get(fileid=fid))
    147         return self._metadata_for_mime_type(self._spreadsheet_mime_type, query, only_team_drive)
    148 

~\Anaconda3\lib\site-packages\googleapiclient\discovery.py in method(self, **kwargs)
   1017         for name in kwargs:
   1018             if name not in parameters.argmap:
-> 1019                 raise TypeError('Got an unexpected keyword argument {}'.format(name))
   1020 
   1021         # Remove args that have a value of None.

TypeError: Got an unexpected keyword argument fileid

System Information

  • OS: Windows
  • pygsheets version : 2.05
  • pygsheets installed from (github or pypi): github

Looks like the worksheet id is being sent wrong. as a workaround you can unlink the cell and call cell.update(wks.id)
Will push a fix.

Love this package and really wanted this feature, so found the bugs

drive.py@146

return self._execute_request(self.service.files().get(fileId=fid)) #FIXME broken fileId
  • 'filled' should be 'fileId' (upper case 'I')

client@124

old_folder = self.drive.spreadsheet_metadata(fid=result['spreadsheetId']).get('parents', [None])[0]
  • remove first "[0]", above line is correct, paste this line over.

I think this PR fixes it #549

Ah gotcha, thanks for the great work btw.

Closing as this is fixed. Please repone if not.

Hi, I encounter the same issue and I am using 2.0.6, but it would work when I use 2.0.5

my code:

import pygsheets


gc = pygsheets.authorize(service_account_file='auth.json')
gc.create(title="test", folder="<folder_id>")

error:

File "/usr/local/lib/python3.10/site-packages/pygsheets/client.py", line 124, in create
    old_folder=self.drive.spreadsheet_metadata(fid=result['spreadsheetId'])[0].get('parents', [None])[0],
KeyError: 0

my environment:
macOS Ventura 13.1
python 3.10.9

This is fixed in the staging version, please use it until the next release. https://github.com/nithinmurali/pygsheets#from-github-recommended