1

Google Drive API不斷向我發送500個錯誤,並且我的想法已經耗盡。Google電子表格API 500er錯誤

的502錯誤頁面返回讀取:

That’s an error. The server encountered a temporary error and could not complete your request. 
Please try again in 30 seconds.   
That’s all we know. 

有時我也得到一個500,其錯誤信息基本上說「不知道」,不甚至建議重試。

我做了一個玩具例子來重現問題:

import gspread 
import random 
import json 
from oauth2client.client import SignedJwtAssertionCredentials 

def main(): 

    json_key = json.load(open("/home/me/.credentials/API Project-56725514b81f.json")) 
    scope = ['https://spreadsheets.google.com/feeds'] 

    credentials = SignedJwtAssertionCredentials(json_key['client_email'], json_key['private_key'], scope) 
    client = gspread.authorize(credentials) 

    #prior to run, create a spreadsheet "Test" with the sheets "Sheet 1", "Sheet 2", "Sheet 3" 
    filename = "Test" 
    spreadsheet = client.open(filename) 
    while True: 
     sheet='Sheet %i' %random.choice([1,2,3]) 
     wks = spreadsheet.worksheet(sheet) 
     range= wks.range('A1:Z1') 
     range[0].value = random.random() 
     range[1].value = random.random() 
     range[2].value = random.random() 
     wks.update_cells(range) 

if __name__ == '__main__': 

    main() 

我測試了以下假設:

  • 超出請求允許的數字 - >我查了Developer Console我的OAuth用戶 - >每天10.000.000個請求被允許,用戶限制也被設置爲高
  • 錯誤消息表明等待可能有所幫助。我按照Api Docs的建議實施了指數退避,但無論等待多久,我都會從gspread中獲得「ResponseNotReady」異常。

更多信息

除 「PRIVATE_KEY」 和 「service_account_name」 憑證對象:

{ 「id_token」:NULL, 「token_uri」: 「https://accounts.google.com/o/oauth2/token」, 「token_response」:NULL,「CLIENT_ID 「:null,」scope「:」https://spreadsheets.google.com/feeds「,」token_expiry「:null,」_class「:」SignedJwtAssertionCredentials「,」refresh_token「:null,」_module「:」oauth2client.client「,」private_key_password「:」notasecret「, 「access_token」:null,「invalid」:false,「assertion_type」:null,「kwargs」:{},「client_secret」:null,「revoke_uri」:「https://accounts.google.com/o/oauth2/revoke」,「store」:null,「user_agent」 }

回答

1

我不確定你正在使用哪個庫,但是行 client = gspread.login([email protected], password) 意味着它是過時的。無法再通過用戶名和密碼向Google API進行身份驗證。

根據您的編程語言,您應該找到更新的庫或直接針對REST API編程。

+0

我知道:)這只是提供一個易於測試的玩具的例子。我使用oauth進行身份驗證(請參閱「我嘗試的」) – Cassandra

+1

我不確定這是「易測試」,因爲它保證不起作用。你可能會更好地粘貼你懷疑應該工作的代碼。此外,它將有助於提供您正在使用的庫的鏈接,因爲正如我所說,它看起來可能已過時。 – pinoyyid

+0

好的。我認爲這樣分析可能會更容易。我將示例代碼更改爲我使用的代碼,錯誤是相同的。我使用gspread https://github.com/burnash/gspread – Cassandra

相關問題