4

How can I check if a Session in Python 3.5 will still be able to handle get() requests? Is there a standard procedure that people use to check for this when sending get() requests with a Session when they reuse the same Session for multiple requests?

Specifically, I'd like to handle ConnectionErrors as efficiently as possible; I have to write code that's supposed to be as high-performance as possible.

Example of an error I'd like to avoid or manage as efficiently as possible:

  File "C:\Anaconda3\lib\site-packages\requests\sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "C:\Anaconda3\lib\site-packages\rauth\session.py", line 210, in request
    return super(OAuth1Session, self).request(method, url, **req_kwargs)
  File "C:\Anaconda3\lib\site-packages\requests\sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\Anaconda3\lib\site-packages\requests\sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "C:\Anaconda3\lib\site-packages\requests\adapters.py", line 426, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
geofurb
  • 489
  • 4
  • 13

1 Answers1

0

It is best to catch the exceptions raised by requests and handle them gracefully (see here), use timeout values and possibly use a retry strategy that fits to your use case, and do unit testing with mocking responses. Not sure what else you mean with manage efficiently.

dh762
  • 2,259
  • 4
  • 25
  • 44