Gspread keep alive after update google auth2

醉酒当歌 提交于 2019-12-07 21:20:02

问题


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'


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!