Python requests.exceptions.RequestException() Examples

The following are 30 code examples for showing how to use requests.exceptions.RequestException(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module requests.exceptions , or try the search function .

Example 1
Project: robotframework-testrail   Author: peterservice-rnd   File: TestRailPreRunModifier.py    License: Apache License 2.0 6 votes vote down vote up
def start_suite(self, suite: TestSuite) -> None:
        """Form list of tests for the Robot Framework test suite that are included in the TestRail test run.

        If analysis depth of the run results is greater than zero, when first suite is launched
        a list of 'testrailid' tags of stable test cases is obtained.
        After that the list of tags is written to the class attribute and for subsequent suites the obtaining is not happening.

        If analysis depth of the run results is zero, when the first suite is launched
        a list of 'testrailid' tags of all test cases in the given status is obtained.
        After that the list of tags is written to the class attribute and for subsequent suites the obtaining is not happening.

        *Args:*\n
            _suite_ - Robot Framework test suite object.
        """
        tests = suite.tests
        suite.tests = None
        try:
            if self.results_depth > 0:
                suite.tests = [t for t in tests if (set(t.tags) & set(self.tr_stable_tags_list))]
            else:
                suite.tests = [t for t in tests if (set(t.tags) & set(self.tr_tags_list))]
        except (RequestException, TimeoutError) as error:
            self._log_to_parent_suite(suite, str(error)) 
Example 2
Project: gphotos-sync   Author: gilesknap   File: GooglePhotosDownload.py    License: MIT License 6 votes vote down vote up
def find_bad_items(self, batch: Mapping[str, DatabaseMedia]):
        """
        a batch get failed. Now do all of its contents as individual
        gets so we can work out which ID(s) cause the failure
        """
        for item_id, media_item in batch.items():
            try:
                log.debug("BAD ID Retry on %s (%s)", item_id, media_item.relative_path)
                response = self._api.mediaItems.get.execute(mediaItemId=item_id)
                media_item_json = response.json()
                self.download_file(media_item, media_item_json)
            except RequestException as e:
                self.bad_ids.add_id(
                    str(media_item.relative_path), media_item.id, media_item.url, e
                )
                self.files_download_failed += 1
                log.error(
                    "FAILURE %d in get of %s BAD ID",
                    self.files_download_failed,
                    media_item.relative_path,
                ) 
Example 3
Project: tap-salesforce   Author: singer-io   File: bulk.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def job_exists(self, job_id):
        try:
            endpoint = "job/{}".format(job_id)
            url = self.bulk_url.format(self.sf.instance_url, endpoint)
            headers = self._get_bulk_headers()

            with metrics.http_request_timer("get_job"):
                self.sf._make_request('GET', url, headers=headers)

            return True # requests will raise for a 400 InvalidJob

        except RequestException as ex:
            if ex.response.headers["Content-Type"] == 'application/json':
                exception_code = ex.response.json()['exceptionCode']
                if exception_code == 'InvalidJob':
                    return False
            raise 
Example 4
Project: tap-salesforce   Author: singer-io   File: __init__.py    License: GNU Affero General Public License v3.0 6 votes vote down vote up
def _make_request(self, http_method, url, headers=None, body=None, stream=False, params=None):
        if http_method == "GET":
            LOGGER.info("Making %s request to %s with params: %s", http_method, url, params)
            resp = self.session.get(url, headers=headers, stream=stream, params=params)
        elif http_method == "POST":
            LOGGER.info("Making %s request to %s with body %s", http_method, url, body)
            resp = self.session.post(url, headers=headers, data=body)
        else:
            raise TapSalesforceException("Unsupported HTTP method")

        try:
            resp.raise_for_status()
        except RequestException as ex:
            raise ex

        if resp.headers.get('Sforce-Limit-Info') is not None:
            self.rest_requests_attempted += 1
            self.check_rest_quota_usage(resp.headers)

        return resp 
Example 5
Project: Penny-Dreadful-Tools   Author: PennyDreadfulMTG   File: repo.py    License: GNU General Public License v3.0 6 votes vote down vote up
def get_pull_requests(start_date: datetime.datetime,
                      end_date: datetime.datetime,
                      max_pull_requests: int = sys.maxsize,
                      repo_name: str = 'PennyDreadfulMTG/Penny-Dreadful-Tools'
                     ) -> List[PullRequest.PullRequest]:
    gh_user = configuration.get_optional_str('github_user')
    gh_pass = configuration.get_optional_str('github_password')
    if gh_user is None or gh_pass is None:
        return []
    g = Github(gh_user, gh_pass)
    git_repo = g.get_repo(repo_name)
    pulls: List[PullRequest.PullRequest] = []
    try:
        for pull in git_repo.get_pulls(state='closed', sort='updated', direction='desc'):
            if not pull.merged_at:
                continue
            merged_dt = dtutil.UTC_TZ.localize(pull.merged_at)
            updated_dt = dtutil.UTC_TZ.localize(pull.updated_at)
            if merged_dt > end_date:
                continue
            if updated_dt < start_date:
                return pulls
            pulls.append(pull)
            if len(pulls) >= max_pull_requests:
                return pulls
    except RequestException as e:
        print('Github pulls error (request)', e)
    except GithubException as e:
        print('Gihub pulls error (github)', e)
    return pulls 
Example 6
Project: insightconnect-plugins   Author: rapid7   File: connection.py    License: MIT License 6 votes vote down vote up
def test(self):
        # list UDSO's
        json_payload = ''
        api_path = "/WebApp/api/SuspiciousObjects/UserDefinedSO/"
        request_url = self.url + api_path
        self.create_jwt_token(api_path, 'GET', json_payload)

        response = None

        try:
            response = requests.get(request_url, headers=self.header_dict, data=json_payload, verify=False)
            response.raise_for_status()
            if response.status_code != 200:
                raise ConnectionTestException(f'{response.text} (HTTP status: {response.status_code})')

            return {"success": True}
        except RequestException as rex:
            if response:
                self.logger.error(f"Received status code: {response.status_code}")
                self.logger.error(f"Response was: {response.text}")
            raise ConnectionTestException(assistance="Please verify the connection details and input data.",
                                          cause=f"Error processing the Apex request: {rex}") 
Example 7
Project: python-sdk   Author: optimizely   File: event_dispatcher.py    License: Apache License 2.0 6 votes vote down vote up
def dispatch_event(event):
        """ Dispatch the event being represented by the Event object.

    Args:
      event: Object holding information about the request to be dispatched to the Optimizely backend.
    """

        try:
            if event.http_verb == enums.HTTPVerbs.GET:
                requests.get(event.url, params=event.params, timeout=REQUEST_TIMEOUT).raise_for_status()
            elif event.http_verb == enums.HTTPVerbs.POST:
                requests.post(
                    event.url, data=json.dumps(event.params), headers=event.headers, timeout=REQUEST_TIMEOUT,
                ).raise_for_status()

        except request_exception.RequestException as error:
            logging.error('Dispatch event failed. Error: %s' % str(error)) 
Example 8
Project: python-sdk   Author: optimizely   File: test_event_dispatcher.py    License: Apache License 2.0 6 votes vote down vote up
def test_dispatch_event__handle_request_exception(self):
        """ Test that dispatch event handles exceptions and logs error. """

        url = 'https://www.optimizely.com'
        params = {
            'accountId': '111001',
            'eventName': 'test_event',
            'eventEntityId': '111028',
            'visitorId': 'oeutest_user',
        }
        event = event_builder.Event(url, params, http_verb='POST', headers={'Content-Type': 'application/json'})

        with mock.patch(
            'requests.post', side_effect=request_exception.RequestException('Failed Request'),
        ) as mock_request_post, mock.patch('logging.error') as mock_log_error:
            event_dispatcher.EventDispatcher.dispatch_event(event)

        mock_request_post.assert_called_once_with(
            url,
            data=json.dumps(params),
            headers={'Content-Type': 'application/json'},
            timeout=event_dispatcher.REQUEST_TIMEOUT,
        )
        mock_log_error.assert_called_once_with('Dispatch event failed. Error: Failed Request') 
Example 9
Project: Dallinger   Author: Dallinger   File: bots.py    License: MIT License 6 votes vote down vote up
def complete_experiment(self, status):
        """Record worker completion status to the experiment server.

        This is done using a GET request to the /worker_complete
        or /worker_failed endpoints.
        """
        self.log("Bot player completing experiment. Status: {}".format(status))
        while True:
            url = "{host}/{status}?participant_id={participant_id}".format(
                host=self.host, participant_id=self.participant_id, status=status
            )
            try:
                result = requests.get(url)
                result.raise_for_status()
            except RequestException:
                self.stochastic_sleep()
                continue
            return result 
Example 10
Project: Dallinger   Author: Dallinger   File: bots.py    License: MIT License 6 votes vote down vote up
def complete_questionnaire(self):
        """Complete the standard debriefing form.

        Answers the questions in the base questionnaire.
        """
        while True:
            data = {
                "question": "questionnaire",
                "number": 1,
                "response": json.dumps(self.question_responses),
            }
            url = "{host}/question/{self.participant_id}".format(
                host=self.host, self=self
            )
            try:
                result = requests.post(url, data=data)
                result.raise_for_status()
            except RequestException:
                self.stochastic_sleep()
                continue
            return True 
Example 11
Project: plugin.video.netflix   Author: CastagnaIT   File: nfsession_access.py    License: MIT License 6 votes vote down vote up
def prefetch_login(self):
        """Check if we have stored credentials.
        If so, do the login before the user requests it"""
        from requests import exceptions
        try:
            common.get_credentials()
            if not self.is_logged_in():
                self._login()
            self.is_prefetch_login = True
        except exceptions.RequestException as exc:
            # It was not possible to connect to the web service, no connection, network problem, etc
            import traceback
            common.error('Login prefetch: request exception {}', exc)
            common.debug(g.py2_decode(traceback.format_exc(), 'latin-1'))
        except MissingCredentialsError:
            common.info('Login prefetch: No stored credentials are available')
        except (LoginFailedError, LoginValidateError):
            ui.show_notification(common.get_local_string(30009))
        except (InvalidMembershipStatusError, InvalidMembershipStatusAnonymous):
            ui.show_notification(common.get_local_string(30180), time=10000) 
Example 12
Project: oanda-api-v20   Author: hootnot   File: test_oandapyv20.py    License: MIT License 6 votes vote down vote up
def test__requests_exception(self):
        """force a requests exception."""
        from requests.exceptions import RequestException
        import oandapyV20.endpoints.accounts as accounts
        setattr(sys.modules["oandapyV20.oandapyV20"],
                "TRADING_ENVIRONMENTS",
                {"practice": {
                 "stream": "ttps://test.com",
                 "api": "ttps://test.com",
                 }})
        api = API(environment=environment,
                  access_token=access_token,
                  headers={"Content-Type": "application/json"})
        text = "No connection " \
               "adapters were found for 'ttps://test.com/v3/accounts'"
        r = accounts.AccountList()
        with self.assertRaises(RequestException) as oErr:
            api.request(r)

        self.assertEqual("{}".format(oErr.exception), text) 
Example 13
Project: ISIC-Archive-Downloader   Author: GalAvineri   File: download_single_item.py    License: Apache License 2.0 6 votes vote down vote up
def fetch_description(url: str) -> list:
        """

        :param id: Id of the image whose description will be downloaded
        :return: Json
        """
        # Sometimes their site isn't responding well, and than an error occurs,
        # So we will retry 10 seconds later and repeat until it succeeds
        while True:
            try:
                # Download the description
                response_desc = requests.get(url, stream=True, timeout=20)
                # Validate the download status is ok
                response_desc.raise_for_status()
                # Parse the description
                parsed_description = response_desc.json()
                return parsed_description
            except (RequestException, ReadTimeoutError):
                time.sleep(5) 
Example 14
Project: epicbox   Author: StepicOrg   File: sandboxes.py    License: MIT License 6 votes vote down vote up
def working_directory():
    docker_client = utils.get_docker_client()
    volume_name = 'epicbox-' + str(uuid.uuid4())
    log = logger.bind(volume=volume_name)
    log.info("Creating new docker volume for working directory")
    try:
        volume = docker_client.volumes.create(volume_name)
    except (RequestException, DockerException) as e:
        log.exception("Failed to create a docker volume")
        raise exceptions.DockerError(str(e))
    log.info("New docker volume is created")
    try:
        yield _WorkingDirectory(volume=volume_name, node=None)
    finally:  # Ensure that volume cleanup takes place
        log.info("Removing the docker volume")
        try:
            volume.remove()
        except NotFound:
            log.warning("Failed to remove the docker volume, it doesn't exist")
        except (RequestException, DockerException):
            log.exception("Failed to remove the docker volume")
        else:
            log.info("Docker volume removed") 
Example 15
Project: epicbox   Author: StepicOrg   File: utils.py    License: MIT License 6 votes vote down vote up
def inspect_exited_container_state(container):
    try:
        container.reload()
    except (RequestException, DockerException) as e:
        logger.exception("Failed to load the container from the Docker engine",
                         container=container)
        raise exceptions.DockerError(str(e))
    started_at = dateutil.parser.parse(container.attrs['State']['StartedAt'])
    finished_at = dateutil.parser.parse(container.attrs['State']['FinishedAt'])
    duration = finished_at - started_at
    duration_seconds = duration.total_seconds()
    if duration_seconds < 0:
        duration_seconds = -1
    return {
        'exit_code': container.attrs['State']['ExitCode'],
        'duration': duration_seconds,
        'oom_killed': container.attrs['State'].get('OOMKilled', False),
    } 
Example 16
Project: nzb-subliminal   Author: caronc   File: __main__.py    License: GNU General Public License v3.0 6 votes vote down vote up
def submit_bug(filename, options):
    import requests  # only import when needed
    from requests.exceptions import RequestException

    try:
        opts = dict((k, v) for k, v in options.__dict__.items()
                    if v and k != 'submit_bug')

        r = requests.post('http://localhost:5000/bugs', {'filename': filename,
                                                         'version': __version__,
                                                         'options': str(opts)})
        if r.status_code == 200:
            print('Successfully submitted file: %s' % r.text)
        else:
            print('Could not submit bug at the moment, please try again later.')

    except RequestException as e:
        print('Could not submit bug at the moment, please try again later.') 
Example 17
Project: netease-dl   Author: ziwenxie   File: download.py    License: MIT License 6 votes vote down vote up
def login(method):
    """Require user to login."""

    def wrapper(*args, **kwargs):
        crawler = args[0].crawler  # args[0] is a NetEase object

        try:
            if os.path.isfile(cookie_path):
                with open(cookie_path, 'r') as cookie_file:
                    cookie = cookie_file.read()
                expire_time = re.compile(r'\d{4}-\d{2}-\d{2}').findall(cookie)
                now = time.strftime('%Y-%m-%d', time.localtime(time.time()))
                if expire_time[0] > now:
                    crawler.session.cookies.load()
                else:
                    crawler.login()
            else:
                crawler.login()
        except RequestException:
            click.echo('Maybe password error, please try again.')
            sys.exit(1)
        result = method(*args, **kwargs)
        return result

    return wrapper 
Example 18
Project: netease-dl   Author: ziwenxie   File: download.py    License: MIT License 6 votes vote down vote up
def download_song_by_id(self, song_id, song_name, folder='.'):
        """Download a song by id and save it to disk.

        :params song_id: song id.
        :params song_name: song name.
        :params folder: storage path.
        """

        try:
            url = self.crawler.get_song_url(song_id)
            if self.lyric:
                # use old api
                lyric_info = self.crawler.get_song_lyric(song_id)
            else:
                lyric_info = None
            song_name = song_name.replace('/', '')
            song_name = song_name.replace('.', '')
            self.crawler.get_song_by_url(url, song_name, folder, lyric_info)
        except RequestException as exception:
            click.echo(exception) 
Example 19
Project: netease-dl   Author: ziwenxie   File: download.py    License: MIT License 6 votes vote down vote up
def download_artist_by_id(self, artist_id, artist_name):
        """Download a artist's top50 songs by his/her id.

        :params artist_id: artist id.
        :params artist_name: artist name.
        """

        try:
            # use old api
            songs = self.crawler.get_artists_hot_songs(artist_id)
        except RequestException as exception:
            click.echo(exception)
        else:
            folder = os.path.join(self.folder, artist_name)
            for song in songs:
                self.download_song_by_id(song.song_id, song.song_name, folder) 
Example 20
Project: netease-dl   Author: ziwenxie   File: download.py    License: MIT License 6 votes vote down vote up
def download_playlist_by_id(self, playlist_id, playlist_name):
        """Download a playlist's songs by its id.

        :params playlist_id: playlist id.
        :params playlist_name: playlist name.
        """

        try:
            songs = self.crawler.get_playlist_songs(
                playlist_id)
        except RequestException as exception:
            click.echo(exception)
        else:
            folder = os.path.join(self.folder, playlist_name)
            for song in songs:
                self.download_song_by_id(song.song_id, song.song_name, folder) 
Example 21
Project: netease-dl   Author: ziwenxie   File: weapi.py    License: MIT License 6 votes vote down vote up
def exception_handle(method):
    """Handle exception raised by requests library."""

    def wrapper(*args, **kwargs):
        try:
            result = method(*args, **kwargs)
            return result
        except ProxyError:
            LOG.exception('ProxyError when try to get %s.', args)
            raise ProxyError('A proxy error occurred.')
        except ConnectionException:
            LOG.exception('ConnectionError when try to get %s.', args)
            raise ConnectionException('DNS failure, refused connection, etc.')
        except Timeout:
            LOG.exception('Timeout when try to get %s', args)
            raise Timeout('The request timed out.')
        except RequestException:
            LOG.exception('RequestException when try to get %s.', args)
            raise RequestException('Please check out your network.')

    return wrapper 
Example 22
Project: pytos   Author: Tufin   File: helpers.py    License: Apache License 2.0 6 votes vote down vote up
def get_user_list(self):
        """
        Get the list of currently configured SecureApp users.
        :return: The list of currently configured SecureApp users.
        :rtype:User_List
        :raise IOError: If there was a communication error.
        """
        logger.info("Getting SecureApp users list.")
        try:
            response_string = self.get_uri("/securechangeworkflow/api/secureapp/repository/users",
                                           expected_status_codes=200).response.content
        except RequestException:
            message = "Failed to GET SecureApp users list"
            logger.critical(message)
            raise IOError(message)
        self._user_list = User_List.from_xml_string(response_string)
        return self._user_list 
Example 23
Project: pytos   Author: Tufin   File: helpers.py    License: Apache License 2.0 6 votes vote down vote up
def get_user_by_id(self, user_id):
        """
        Get the SecureApp user whose ID matches the specified ID.
        :param user_id: The ID for the user which will be returned.
        :type user_id: int
        :return: The user whose ID matches the specified ID.
        :rtype:User
        :raise ValueError: If an user with the specified ID is not found.
        :raise IOError: If there was a communication error.
        """
        logger.info("Getting SecureApp users with ID '%s'.", user_id)
        try:
            response_string = self.get_uri("/securechangeworkflow/api/secureapp/repository/users/{}".format(user_id),
                                           expected_status_codes=200).response.content
        except REST_Not_Found_Error:
            message = "User with ID '{}' does not exist.".format(user_id)
            logger.critical(message)
            raise ValueError(message)
        except RequestException:
            message = "Failed to GET SecureApp users list."
            logger.critical(message)
            raise IOError(message)
        return User.from_xml_string(response_string) 
Example 24
Project: threat_intel   Author: Yelp   File: http.py    License: MIT License 5 votes vote down vote up
def map_with_retries(self, requests, responses_for_requests):
        """Provides session-based retry functionality

        :param requests: A collection of Request objects.
        :param responses_for_requests: Dictionary mapping of requests to responses
        :param max_retries: The maximum number of retries to perform per session
        :param args: Additional arguments to pass into a retry mapping call


        """
        retries = []
        response_futures = [preq.callable() for preq in requests]

        for request, response_future in zip(requests, response_futures):
            try:
                response = response_future.result()
                if response is not None and response.status_code == 403:
                    logging.warning('Request to {} caused a 403 response status code.'.format(request.url))
                    raise InvalidRequestError('Access forbidden')
                if response is not None:
                    responses_for_requests[request] = response
            except RequestException as re:
                logging.error('An exception was raised for {}: {}'.format(request.url, re))
                if self.total_retries > 0:
                    self.total_retries -= 1
                    retries.append(request)

        # Recursively retry failed requests with the modified total retry count
        if retries:
            self.map_with_retries(retries, responses_for_requests) 
Example 25
Project: gphotos-sync   Author: gilesknap   File: GooglePhotosDownload.py    License: MIT License 5 votes vote down vote up
def download_batch(self, batch: Mapping[str, DatabaseMedia]):
        """ Downloads a batch of media items collected in download_photo_media.

        A fresh 'base_url' is required since they have limited lifespan and
        these are obtained by a single call to the service function
        mediaItems.batchGet.
        """
        try:
            response = self._api.mediaItems.batchGet.execute(mediaItemIds=batch.keys())
            r_json = response.json()
            if r_json.get("pageToken"):
                log.error("Ops - Batch size too big, some items dropped!")

            for i, result in enumerate(r_json["mediaItemResults"]):
                media_item_json = result.get("mediaItem")
                if not media_item_json:
                    log.warning("Null response in mediaItems.batchGet %s", batch.keys())
                    log.debug(
                        "Null response in mediaItems.batchGet"
                        "for item %d in\n\n %s \n\n which is \n%s",
                        i,
                        str(r_json),
                        str(result),
                    )
                else:
                    media_item = batch.get(media_item_json["id"])
                    self.download_file(media_item, media_item_json)
        except RequestException:
            self.find_bad_items(batch)

        except KeyboardInterrupt:
            log.warning("Cancelling download threads ...")
            for f in self.pool_future_to_media:
                f.cancel()
            futures.wait(self.pool_future_to_media)
            log.warning("Cancelled download threads")
            raise 
Example 26
Project: tap-salesforce   Author: singer-io   File: sync.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def sync_stream(sf, catalog_entry, state):
    stream = catalog_entry['stream']

    with metrics.record_counter(stream) as counter:
        try:
            sync_records(sf, catalog_entry, state, counter)
            singer.write_state(state)
        except RequestException as ex:
            raise Exception("Error syncing {}: {} Response: {}".format(
                stream, ex, ex.response.text))
        except Exception as ex:
            raise Exception("Error syncing {}: {}".format(
                stream, ex)) from ex

        return counter 
Example 27
Project: sncli   Author: insanum   File: simplenote.py    License: MIT License 5 votes vote down vote up
def delete_note(self, note_id):
        """ method to permanently delete a note

        Arguments:
            - note_id (string): key of the note to trash

        Returns:
            A tuple `(note, status)`

            - note (dict): an empty dict or an error message
            - status (int): 0 on sucesss and -1 otherwise

        """
        # notes have to be trashed before deletion
        note, status = self.trash_note(note_id)
        if (status == -1):
            return note, status

        try:
            # self.api is obviously ok if self.trash_note worked
            self.api.note.delete(note_id)
        except ConnectionError as e:
            self.status = 'offline, connection error'
            return e, -1
        except RequestException as e:
            return e, -1
        return {}, 0 
Example 28
Project: pygreynoise   Author: GreyNoise-Intelligence   File: decorator.py    License: MIT License 5 votes vote down vote up
def handle_exceptions(function):
    """Print error and exit on API client exception.

    :param function: Subcommand that returns a result from the API.
    :type function: callable
    :returns: Wrapped function that prints subcommand results
    :rtype: callable

    """

    @functools.wraps(function)
    def wrapper(*args, **kwargs):
        try:
            return function(*args, **kwargs)
        except RequestFailure as exception:
            body = exception.args[1]
            error_message = "API error: {}".format(body["error"])
            LOGGER.error(error_message)
            click.echo(error_message)
            click.get_current_context().exit(-1)
        except RequestException as exception:
            error_message = "API error: {}".format(exception)
            LOGGER.error(error_message)
            click.echo(error_message)
            click.get_current_context().exit(-1)

    return wrapper 
Example 29
Project: pygreynoise   Author: GreyNoise-Intelligence   File: test_subcommand.py    License: MIT License 5 votes vote down vote up
def test_requests_exception(self, api_client):
        """Error is displayed on requests library exception."""
        runner = CliRunner()
        expected = "API error: <error message>\n"

        api_client.analyze.side_effect = RequestException("<error message>")
        result = runner.invoke(subcommand.analyze, input="some text")
        assert result.exit_code == -1
        assert result.output == expected 
Example 30
Project: pygreynoise   Author: GreyNoise-Intelligence   File: test_subcommand.py    License: MIT License 5 votes vote down vote up
def test_requests_exception(self, api_client):
        """Error is displayed on requests library exception."""
        runner = CliRunner()
        expected = "API error: <error message>\n"

        api_client.filter.side_effect = RequestException("<error message>")
        result = runner.invoke(subcommand.filter, input="some text")
        assert result.exit_code == -1
        assert result.output == expected