How to use the urllib3.exceptions.ReadTimeoutError function in urllib3

To help you get started, we’ve selected a few urllib3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github polyaxon / polyaxon / tests / test_builder.py View on Github external
def test_push_raise_timeout(self, build_mock, push_mock):
        push_mock.side_effect = ReadTimeoutError(None, 'foo', 'error')
        with self.assertRaises(BuildException):
            build_and_push(build_context='.',
                           image_tag='image_tag',
                           image_name='image_name',
                           nocache=True,
                           max_retries=1,
                           sleep_interval=0)
        assert build_mock.call_count == 1
github demisto / content / Tests / test_integration.py View on Github external
response_code = 0
    print_warning("trying to connect.")
    for i in range(connection_retries):
        try:
            response_data, response_code, _ = demisto_client.generic_request_func(self=client, method='POST',
                                                                                  path='/settings/integration/test',
                                                                                  body=module_instance,
                                                                                  _request_timeout=120)
            break
        except ApiException as conn_err:
            print_error(
                'Failed to test integration instance, error trying to communicate with demisto '
                'server: {} '.format(
                    conn_err))
            return False, None
        except urllib3.exceptions.ReadTimeoutError:
            print_warning("Could not connect. Trying to connect for the {} time".format(i + 1))

    if int(response_code) != 200:
        print_error('Integration-instance test ("Test" button) failed.\nBad status code: ' + str(
            response_code))
        return False, None

    result_object = ast.literal_eval(response_data)
    success, failure_message = bool(result_object.get('success')), result_object.get('message')
    if not success:
        if failure_message:
            print_error('Test integration failed.\nFailure message: {}'.format(failure_message))
        else:
            print_error('Test integration failed\nNo failure message.')
    return success, failure_message
github houtianze / bypy / bypy / bypy.py View on Github external
# https://github.com/shazow/urllib3/pull/412
# it was fixed here:
# https://github.com/shazow/urllib3/pull/413
# commit:
# https://github.com/shazow/urllib3/commit/a89dda000ed144efeb6be4e0b417c0465622fe3f
# and this was included in this commit in the Requests library
# https://github.com/kennethreitz/requests/commit/7aa6c62d6d917e11f81b166d1d6c9e60340783ac
# which was included in version 2.5.0 or above
# so minimum 2.5.0 is required
import requests
try:
	from requests.packages.urllib3.exceptions import ReadTimeoutError
except:
	try:
		from urllib3.exceptions import ReadTimeoutError
		ReadTimeoutError
	except:
		perr("Something seems wrong with the urllib3 installation.\nQuitting")
		sys.exit(const.EFatal)

from requests_toolbelt import multipart

# http://stackoverflow.com/a/27320254/404271
try:
	import multiprocess as mp
	from multiprocess import Pool
except ImportError:
	mp = None
	Pool = None
	perr("'multiprocess' library is not available, no parallel dl/ul.")

UPool = None
github lorien / grab / grab / transport / urllib3.py View on Github external
def wrap_transport_error(self):
        try:
            yield
        except exceptions.ReadTimeoutError as ex:
            raise error.GrabTimeoutError('ReadTimeoutError', ex)
        except exceptions.ConnectTimeoutError as ex:
            raise error.GrabConnectionError('ConnectTimeoutError', ex)
        except exceptions.ProtocolError as ex:
            # TODO:
            # the code
            # raise error.GrabConnectionError(ex.args[1][0], ex.args[1][1])
            # fails
            # with error TypeError: 'OSError' object is not subscriptable
            raise error.GrabConnectionError('ProtocolError', ex)
        except exceptions.SSLError as ex:
            raise error.GrabConnectionError('SSLError', ex)
        except ssl.SSLError as ex:
            raise error.GrabConnectionError('SSLError', ex)
github stanislav-web / OpenDoor / src / core / http / http.py View on Github external
headers=self._headers,
                                                 retries=self.__cfg.retries,
                                                 assert_same_host=False,
                                                 redirect=False)
            return response

        except MaxRetryError:
            if self.__cfg.DEFAULT_SCAN == self.__cfg.scan:
                self.__tpl.warning(key='max_retry_error', url=helper.parse_url(url).path)
            pass

        except HostChangedError as error:
            self.__tpl.warning(key='host_changed_error', details=error)
            pass

        except ReadTimeoutError:
            self.__tpl.warning(key='read_timeout_error', url=url)
            pass

        except ConnectTimeoutError:
            self.__tpl.warning(key='connection_timeout_error', url=url)
            pass
github Alexey-T / CudaText / app / py / requests / models.py View on Github external
def generate():
            # Special case for urllib3.
            if hasattr(self.raw, 'stream'):
                try:
                    for chunk in self.raw.stream(chunk_size, decode_content=True):
                        yield chunk
                except ProtocolError as e:
                    raise ChunkedEncodingError(e)
                except DecodeError as e:
                    raise ContentDecodingError(e)
                except ReadTimeoutError as e:
                    raise ConnectionError(e)
            else:
                # Standard file-like object.
                while True:
                    chunk = self.raw.read(chunk_size)
                    if not chunk:
                        break
                    yield chunk

            self._content_consumed = True
github collective / collective.elasticsearch / collective / elasticsearch / hook.py View on Github external
def index_batch_async(remove, index, positions):
        retries = 0
        while True:
            # if doing batch updates, this can give ES problems
            if retries < 4:
                try:
                    index_batch(remove, index, positions)
                    break
                except urllib3.exceptions.ReadTimeoutError:
                    retries += 1
                    if retries >= 4:
                        raise
                    time.sleep(random.choice([0.5, 0.75, 1, 1.25, 1.5]))
github Netherdrake / py-eos-api / eosapi / http_client.py View on Github external
""" Execute a method against eosd RPC.

        Warnings:
            This command will auto-retry in case of node failure, as well as handle
            node fail-over, unless we are broadcasting a transaction.
            In latter case, the exception is **re-raised**.
        """

        url = f"{self.node_url}/{self.api_version}/{api}/{endpoint}"
        body = self._body(body)
        method = 'POST' if body else 'GET'
        try:
            response = self.http.urlopen(method, url, body=body)
        except (MaxRetryError,
                ConnectionResetError,
                ReadTimeoutError,
                RemoteDisconnected,
                ProtocolError) as e:

            if _ret_cnt >= self.max_retries:
                raise e

            # try switching nodes before giving up
            time.sleep(_ret_cnt)
            self.next_node()
            logging.debug('Switched node to %s due to exception: %s' %
                          (self.hostname, e.__class__.__name__))
            return self.exec(api, endpoint, body, _ret_cnt=_ret_cnt + 1)
        except Exception as e:
            extra = dict(err=e, url=url, body=body, method=method)
            logger.info('Request error', extra=extra)
            raise e
github simplecrypto / cryptokit / cryptokit / rpc.py View on Github external
def __call__(self, *args):
        self._id_count += 1

        postdata = json.dumps({'version': '1.1',
                               'method': self._service_name,
                               'params': args,
                               'id': self._id_count})
        try:
            response = self._conn.urlopen('POST', self._url.path, postdata)

        except urllib3.exceptions.MaxRetryError:
            raise CoinRPCException({
                'code': -24, 'message': 'RPC connection failed, maximum retries'
                                        ' exceeded.'})
        except urllib3.exceptions.ReadTimeoutError:
            raise CoinRPCException({
                'code': -25, 'message': 'RPC connection failed, maximum time '
                                        'spent waiting for a response was '
                                        'exceeded'})
        except urllib3.exceptions.HTTPError as e:
            raise CoinRPCException({
                'code': -23, 'message': 'Unable to connect to server: '
                                        '{}'.format(e)})
        return self._get_response(response)
github ColdGrub1384 / Pyto / site-packages / requests / adapters.py View on Github external
# This branch is for urllib3 v1.22 and later.
                raise SSLError(e, request=request)

            raise ConnectionError(e, request=request)

        except ClosedPoolError as e:
            raise ConnectionError(e, request=request)

        except _ProxyError as e:
            raise ProxyError(e)

        except (_SSLError, _HTTPError) as e:
            if isinstance(e, _SSLError):
                # This branch is for urllib3 versions earlier than v1.22
                raise SSLError(e, request=request)
            elif isinstance(e, ReadTimeoutError):
                raise ReadTimeout(e, request=request)
            else:
                raise

        return self.build_response(request, resp)