New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not reusing HTTP connections via a pool? #380
Comments
Can you post some code details here as to where we should insert this line? |
Sure -- I'll create a pull request off of a fork at some point soon. |
the reason i am asking is because i keep getting the below error bcus of API limits i think. Not sure if this the right place to ask , have you come accross such an error? if so whats the solution? So far i have tried to introduce sleep time of 10 seconds between requests. But i still keep getting this error frequently
|
Hmm .. I have not seen that error but reusing HTTP connections would definitely help and not hurt here. |
exactly why i need to know where i should insert ur code... below is the httpsession.py file from gspread library. ..where should i insert the code to re-use http sessions?
This module contains a class for working with http sessions. """ import requests try: from .exceptions import HTTPError class HTTPSession(object):
|
…not recreated upon every request to a spreadsheet. Without this fix, you see following log message on every request to a spreadsheet: ...INFO|requests.packages.urllib3.connectionpool|connectionpool.py:756|_new_conn()|Starting new HTTPS connection (1): spreadsheets.google.com Creationg HTTPS connections is expensive. So this fix impoves the overall performance significantly. See issue burnash#380.
Here you go: #381 |
Awesome this worked. Thanks |
The fix will be on PyPI with the next release. |
Seems like operations on the same client object (logged in just once at the start) continues to create new HTTP request sessions because gspread.HTTPSession doesn't try to actually create a HTTP session with connection pooling.
So you end up seeing one of these reconnects on every operation:
...INFO|requests.packages.urllib3.connectionpool|connectionpool.py:756|_new_conn()|Starting new HTTPS connection (1): spreadsheets.google.com
I would recommend doing following inside HTTPSession's init():
self.requests_session = requests.Session()
.. then reusing it rather than asking requests package methods to create new session every time.
The text was updated successfully, but these errors were encountered: