codepost-python icon indicating copy to clipboard operation
codepost-python copied to clipboard

Handle temporary connection errors gracefully

Open jlumbroso opened this issue 4 years ago • 0 comments

The error log below is okay, but happened for arbitrary error, not clear if there was a retry. May consider catching these types of errors for better reporting?

------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------
RemoteDisconnected                        Traceback (most recent call last)
~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    664             # Make the request on the httplib connection object.
--> 665             httplib_response = self._make_request(
    666                 conn,

~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    420                     # Otherwise it looks like a bug in the code.
--> 421                     six.raise_from(e, None)
    422         except (SocketTimeout, BaseSSLError, SocketError) as e:

~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/urllib3/packages/six.py in raise_from(value, from_value)

~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/urllib3/connectionpool.py in _make_request(self, conn, method, url, timeout, chunked, **httplib_request_kw)
    415                 try:
--> 416                     httplib_response = conn.getresponse()
    417                 except BaseException as e:

/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py in getresponse(self)
   1321             try:
-> 1322                 response.begin()
   1323             except ConnectionError:

/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py in begin(self)
    302         while True:
--> 303             version, status, reason = self._read_status()
    304             if status != CONTINUE:

/opt/local/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/http/client.py in _read_status(self)
    271             # sending a valid response.
--> 272             raise RemoteDisconnected("Remote end closed connection without"
    273                                      " response")

RemoteDisconnected: Remote end closed connection without response

During handling of the above exception, another exception occurred:

MaxRetryError                             Traceback (most recent call last)
~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    438             if not chunked:
--> 439                 resp = conn.urlopen(
    440                     method=request.method,

~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/urllib3/connectionpool.py in urlopen(self, method, url, body, headers, retries, redirect, assert_same_host, timeout, pool_timeout, release_conn, chunked, body_pos, **response_kw)
    718 
--> 719             retries = retries.increment(
    720                 method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]

~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/urllib3/util/retry.py in increment(self, method, url, response, error, _pool, _stacktrace)
    435         if new_retry.is_exhausted():
--> 436             raise MaxRetryError(_pool, url, error or ResponseError(cause))
    437 

MaxRetryError: HTTPSConnectionPool(host='api.codepost.io', port=443): Max retries exceeded with url: /submissionTests/149717/ (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))

During handling of the above exception, another exception occurred:

ProxyError                                Traceback (most recent call last)
<ipython-input-37-0ba20f823506> in <module>
      2     print("-", end="")
      3     if submission.id not in test_passed_by_submission_id:
----> 4         test_passed_by_submission_id[submission.id] = sum(map(
      5             lambda test: 1 if test.passed and get_category_from_testcase(test) == "Correctness" else 0,
      6             submission.tests))

<ipython-input-37-0ba20f823506> in <lambda>(test)
      3     if submission.id not in test_passed_by_submission_id:
      4         test_passed_by_submission_id[submission.id] = sum(map(
----> 5             lambda test: 1 if test.passed and get_category_from_testcase(test) == "Correctness" else 0,
      6             submission.tests))
      7 

~/GoogleDrive/Programming/codepost/sdk/codepost-python/codepost/models/abstract/lazy.py in __getattribute__(self, attr)
    100                 # Fetch object and cache
    101                 try:
--> 102                     self._inner = cls().retrieve(id=id)
    103                 except _errors.NotFoundAPIError:
    104                     self._null = True

~/GoogleDrive/Programming/codepost/sdk/codepost-python/codepost/models/abstract/api_crud.py in retrieve(self, id)
     92             raise _errors.InvalidIDError()
     93 
---> 94         ret = self._requestor._request(
     95             endpoint=self.instance_endpoint_by_id(id=_id),
     96             method="GET",

~/GoogleDrive/Programming/codepost/sdk/codepost-python/codepost/api_requestor.py in _request(self, endpoint, method, **kwargs)
    197                 kws["data"] = _json.dumps(kws["data"])
    198 
--> 199         ret = self._client.request(
    200             url=urljoin(self._base_url, endpoint),
    201             **kws

<boltons.funcutils.FunctionBuilder-2> in request(self, url, method, headers, **kwargs)

~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/eliot/_action.py in logging_wrapper(*args, **kwargs)
    922 
    923         with start_action(action_type=action_type, **callargs) as ctx:
--> 924             result = wrapped_function(*args, **kwargs)
    925             if include_result:
    926                 ctx.add_success_fields(result=result)

~/GoogleDrive/Programming/codepost/sdk/codepost-python/codepost/http_client.py in request(self, url, method, headers, **kwargs)
    213         except Exception as e:
    214             log_action.finish(exception=e)
--> 215             self._handle_request_error(e)
    216 
    217         log_action.finish()

~/GoogleDrive/Programming/codepost/sdk/codepost-python/codepost/http_client.py in _handle_request_error(self, e)
    222         # Meant to handle HTTP/socket-level errors
    223         # API errors are handled in APIRequestor
--> 224         raise e
    225 
    226     def close(self):

~/GoogleDrive/Programming/codepost/sdk/codepost-python/codepost/http_client.py in request(self, url, method, headers, **kwargs)
    179             try:
    180                 with log_action.context():
--> 181                     ret = session.request(
    182                         method=method,
    183                         url=url,

~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/requests/sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    528         }
    529         send_kwargs.update(settings)
--> 530         resp = self.send(prep, **send_kwargs)
    531 
    532         return resp

~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/requests/sessions.py in send(self, request, **kwargs)
    641 
    642         # Send the request
--> 643         r = adapter.send(request, **kwargs)
    644 
    645         # Total elapsed time of the request (approximately)

~/.local/share/virtualenvs/pylifttk-jrMvvMYL/lib/python3.8/site-packages/requests/adapters.py in send(self, request, stream, timeout, verify, cert, proxies)
    508 
    509             if isinstance(e.reason, _ProxyError):
--> 510                 raise ProxyError(e, request=request)
    511 
    512             if isinstance(e.reason, _SSLError):

ProxyError: HTTPSConnectionPool(host='api.codepost.io', port=443): Max retries exceeded with url: /submissionTests/149717/ (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response')))

jlumbroso avatar Mar 13 '20 22:03 jlumbroso