python gspread google spreadsheet keeping connection alive

旧城冷巷雨未停 提交于 2019-12-05 11:02:01

For keeping alive connection you should use persistent connection.

So if you check main document:

http://burnash.github.io/gspread/#gspread.Client

You will see the gspread.login method is instance of Client. and Client can accept http headers.

http://burnash.github.io/gspread/#gspread.httpsession.HTTPSession

Now add this header in your connection : Connection: Keep-Alive

import gspread
headers = gspread.httpsession.HTTPSession(headers={'Connection':'Keep-Alive'})
con = gspread.Client(auth=('you@gmail.com','password'),http_session=headers)
con.login()
con.open_by_key('....')

Then when you get print of session headers:

print con.session.headers
Out[5]: {'Authorization': u'GoogleLogin auth=xxxxxxx', 'Connection': 'Keep-Alive'}

For persistent connection details have a look into these links:

http://en.wikipedia.org/wiki/HTTP_persistent_connection

http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html

For codes details of gspread httpsession have a look into:

https://github.com/burnash/gspread/blob/master/gspread/httpsession.py

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