python - 在 Team Drive 和 Colab 中创建新电子表格时未找到 Gspread 文件错误
问题描述
我在 Google Colab 工作,试图处理一些数据并将其作为 Google 电子表格保存到我管理的团队驱动器中。我正在使用 gspread 3.6.0。
我试图保存的文件夹已经存在(我自己创建了它)。这是我的测试代码:
#Authentication
from google.colab import auth
auth.authenticate_user()
import gspread
from oauth2client.client import GoogleCredentials
gc = gspread.authorize(GoogleCredentials.get_application_default())
test_df = pd.DataFrame(np.random.randint(0,100,size=(100, 4)), columns=list('ABCD'))
folder_id = '1piOfOFFw60hh5SbC9gIPAveCk90thI9_'
sh = gc.create('test_df', folder_id=folder_id)
gspread 抛出的错误如下:
---------------------------------------------------------------------------
APIError Traceback (most recent call last)
<ipython-input-38-a6c430392153> in <module>()
2 folder_id = '1L_ZYzDHi59yHNo2F0ZF8BnQCWJQEu9zR'
3
----> 4 sh = gc.create('df_prueba', folder_id=folder_id)
1 frames
/usr/local/lib/python3.6/dist-packages/gspread/client.py in create(self, title, folder_id)
194 payload['parents'] = [folder_id]
195
--> 196 r = self.request('post', DRIVE_FILES_API_V3_URL, json=payload)
197 spreadsheet_id = r.json()['id']
198 return self.open_by_key(spreadsheet_id)
/usr/local/lib/python3.6/dist-packages/gspread/client.py in request(self, method, endpoint, params, data, json, files, headers)
71 return response
72 else:
---> 73 raise APIError(response)
74
75 def list_spreadsheet_files(self, title=None):
APIError: {'errors': [{'domain': 'global', 'reason': 'notFound', 'message': 'File not found: 1L_ZYzDHi59yHNo2F0ZF8BnQCWJQEu9zR.', 'locationType': 'parameter', 'location': 'fileId'}], 'code': 404, 'message': 'File not found: 1L_ZYzDHi59yHNo2F0ZF8BnQCWJQEu9zR.'}
我从团队驱动器中读取文件没有问题。
如果我将 folder_id 更改为我的驱动器中的文件夹,则代码有效。我检查了 gspread 文档,但我没有在 API 中找到任何与团队驱动器特别相关的参数。
有什么线索吗?
解决方案
我有这个确切的问题。我们能够通过更新 gspread, 来解决它pip install -U gspread
。(我们从 3.6.0 升级到 4.0.1)
推荐阅读
- java - 在 aws 中部署应用程序会引发错误 java.sql.SQLException: No database selected
- python - 在 matplotlib 中保存动画
- javascript - 我如何使用键盘输入更改精灵我正在使用 vanilla JS
- c++ - C++ 使用 operator<< 输出作为函数中的参数
- azure - Azure ML Studio 中的字母识别错误
- java - 不等待线程池上可用线程的任务
- python - Python Pandas 将列截断为特定长度而不剪切最后一个单词
- spring-boot - 部分更新而不从数据库中检索对象
- ubuntu - 为什么我来自 Docker Hub 的 ubuntu 映像附带 4.19 Linux 内核?
- visual-studio-2019 - 视觉工作室 2019 16.7.3