All commands of gspread send requests?
Here error 429 doesnt raise
gc = gs.service_account(filename="service_files/creds.json")
wks = gc.open_by_key("url have 35 list")
article = []
price = []
batch_data = wks.worksheets()
for data in batch_data:
article.extend(data.col_values(3))
price.extend(data.col_values(4))
print(article)
But Here error raises
gc = gs.service_account(filename="service_files/creds.json")
article = []
price = []
for i in range(1,35):
wks = gc.open_by_key("url have 35 list").get_worksheet(i)
article.extend(wks.col_values(3))
price.extend(wks.col_values(4))
print(article)
How does this work? In the first example, we send request once, right? In the second example we send request 35 times, 35 request per user less than 60 request per user, yeah?
What if col_values send request, why first example work?
col_values
sends request to server each time as seen in code.
Also, open_by_key
uses get_sheet_metadata()
, which makes another call.
In addition, get_worksheet
also seems to call get_sheet_metadata
. This isn't cached in the first call AFAICS. The reasoning provided by the contributor is here.
So, total calls is almost double in the second code:
Function | First code | Second code |
---|---|---|
col_values(3) | 35 | 35 |
col_values(4) | 35 | 35 |
open_by_key() | 1 | 35 |
worksheets() | 1 | 0 |
get_worksheet() | 0 | 35 |
Total | 72 | 140 |
As written in the docs, the only relevant calls that are batched seems to get()
, get_all_values()
and batch_get()
:
https://docs.gspread.org/en/v6.1.3/user-guide.html#getting-all-values-from-a-row-or-a-column