I'm using the Gmail API to pull all the emails in a user's inbox. Everything works fine until about an hour, when the request stops returning a response with messages.
I use this code to request message headers:
sess = requests.Session()
retries = Retry(total=5, connect=10, backoff_factor=0.1, status_forcelist=[401, 500, 502, 503, 504], raise_on_redirect=True, raise_on_status=True)
sess.mount('https://', HTTPAdapter(max_retries=retries))
try:
msg = json.loads(sess.get(message_url, params={'format': 'metadata'}, headers=authorization_header).text)
logger.info('msg', dict(msg=msg))
except requests.HTTPError as e:
logger.info('error', dict(
error=e,
error_code=e.code
))
except:
logger.info('Unknown error')
And after an hour I'll get an error like so:
[2017-01-08 16:34:17,536: WARNING/PoolWorker-1]
Retrying (Retry(total=4, connect=10, read=None, redirect=None))
after connection broken by 'ProtocolError('Connection aborted.',
OSError(50, 'Network is down'))':
/gmail/v1/users/<user_id>/messages/<message_id>?format=metadata
I thought I might be running into the issue because the access token expires, so I wrote a script to use the refresh token to get a new access token. The process also never catches the HTTPError, but instead prints 'Unknown error', so I don't think HTTPError would be the case.
Do you have any thoughts on how to approach this issue?