There are several examples for 'keep the connection with google spreadsheet alive' But all I found are based on the 'old' Google Sign-In system which isn't work anymore since april 2015
What is the proper methode to keep the connection with googlespreadsheet alive using OAuth 2.0
I've Tried this
import gspread
from oauth2client.service_account import ServiceAccountCredentials
headers = gspread.httpsession.HTTPSession(headers={'Connection':'Keep-Alive'}) #Allows a persistant connection.
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('Apps Script Execution API.json', scope)
c = gspread.authorize(auth=credentials,http_session=headers)
result: c = gspread.authorize(auth=credentials,http_session=headers) TypeError: authorize() got an unexpected keyword argument 'auth'
A late answer to your question is:
import gspread
from gspread.httpsession import HTTPSession
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
key_name = 'something.json'
credentials = ServiceAccountCredentials.from_json_keyfile_name(key_name, scope)
#gc = gspread.authorize(credentials) doesn't have a http_session kwarg
http_session = HTTPSession(headers={'Connection':'Keep-Alive'})
gc = gspread.Client(credentials, http_session)
gc.login()
ss = gc.open("Sachibondu-MasonryVaults")
来源:https://stackoverflow.com/questions/36786253/gspread-keep-alive-after-update-google-auth2