added session rebuilding to test possible fix for requests.ConnectionError happening after long sleep
This commit is contained in:
parent
0b3df413d8
commit
9e51c7fba9
1 changed files with 18 additions and 3 deletions
|
|
@ -8,8 +8,8 @@ This module contains functionality for access to core Twitter API calls,
|
||||||
Twitter Authentication, and miscellaneous methods that are useful when
|
Twitter Authentication, and miscellaneous methods that are useful when
|
||||||
dealing with the Twitter API
|
dealing with the Twitter API
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import warnings
|
import warnings
|
||||||
|
import logging
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from requests.auth import HTTPBasicAuth
|
from requests.auth import HTTPBasicAuth
|
||||||
|
|
@ -25,7 +25,6 @@ from .helpers import _transparent_params
|
||||||
|
|
||||||
warnings.simplefilter('always', TwythonDeprecationWarning) # For Python 2.7 >
|
warnings.simplefilter('always', TwythonDeprecationWarning) # For Python 2.7 >
|
||||||
|
|
||||||
|
|
||||||
class Twython(EndpointsMixin, object):
|
class Twython(EndpointsMixin, object):
|
||||||
def __init__(self, app_key=None, app_secret=None, oauth_token=None,
|
def __init__(self, app_key=None, app_secret=None, oauth_token=None,
|
||||||
oauth_token_secret=None, access_token=None,
|
oauth_token_secret=None, access_token=None,
|
||||||
|
|
@ -163,6 +162,22 @@ class Twython(EndpointsMixin, object):
|
||||||
try:
|
try:
|
||||||
response = func(url, **requests_args)
|
response = func(url, **requests_args)
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
|
logging.exception('RequestException encountered - refreshing...')
|
||||||
|
# Rebuild Session and retry
|
||||||
|
s2 = requests.Session()
|
||||||
|
s2.auth = self.client.auth
|
||||||
|
s2.headers = self.client.headers
|
||||||
|
s2.cert = self.client.cert
|
||||||
|
s2.hooks = self.client.hooks
|
||||||
|
s2.proxies = self.client.proxies
|
||||||
|
s2.max_redirects = self.client.max_redirects
|
||||||
|
self.client.close()
|
||||||
|
|
||||||
|
self.client = s2
|
||||||
|
try:
|
||||||
|
response = func(url, **requests_args)
|
||||||
|
except requests.RequestException as e:
|
||||||
|
logging.exception('RequestException encountered after refresh!')
|
||||||
raise TwythonError(str(e))
|
raise TwythonError(str(e))
|
||||||
|
|
||||||
# create stash for last function intel
|
# create stash for last function intel
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue