我需要一个 API 来帮助我从 Google 表格中检索数据,因此我尝试使用 GSpread 从单个工作表中检索 3000 多行,我花了几分钟等待数据打印出来。但是,在某些情况下,即使我等待了 10 多分钟,数据仍然没有显示。奇怪的部分是 10 分钟后,当我尝试通过单击 Ctrl+C 来中断程序时,该过程结束而没有任何错误并打印了完整的数据。我还尝试在运行程序 1 分钟后中断程序,但它显示了一些错误消息并且没有显示任何数据。
它是 GSpread 中的错误还是在 Google 表格中检索数千行的正常现象?程序如何在数据检索完成后自动结束?
这是我的代码(我只是按照文档进行操作):
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)
sheet = client.open('Sample Sheet').worksheet('First Worksheet')
data = sheet.get_all_records()
print(data)
而且由于我要检索超过一千行代码,有没有比 GSpread API 更好、更高效的替代方案,它在从 Google Sheets 检索数据到 Python 时也更快?因为我不想等待数据被检索超过 10 分钟。
提前致谢!