当前位置: 首页>>代码示例>>Python>>正文


Python IngestApiError.apiParseError方法代码示例

本文整理汇总了Python中superdesk.errors.IngestApiError.apiParseError方法的典型用法代码示例。如果您正苦于以下问题:Python IngestApiError.apiParseError方法的具体用法?Python IngestApiError.apiParseError怎么用?Python IngestApiError.apiParseError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在superdesk.errors.IngestApiError的用法示例。


在下文中一共展示了IngestApiError.apiParseError方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_tree

# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiParseError [as 别名]
    def _get_tree(self, endpoint, payload=None):
        """Get xml response for given API endpoint and payload.

        :param: endpoint
        :type endpoint: str
        :param: payload
        :type payload: str
        """

        if payload is None:
            payload = {}

        payload['token'] = self._get_auth_token(self.provider, update=True)
        url = self._get_absolute_url(endpoint)

        if not self.session:
            self.session = requests.Session()

        retries = 0
        while True:
            try:
                response = self.session.get(url, params=payload, timeout=(30, 15))
            except requests.exceptions.Timeout as ex:
                if retries < 3:
                    logger.warn('Reuters API timeout retrying, retries {}'.format(retries))
                    retries += 1
                    continue
                raise IngestApiError.apiTimeoutError(ex, self.provider)
            except requests.exceptions.TooManyRedirects as ex:
                # Tell the user their URL was bad and try a different one
                raise IngestApiError.apiRedirectError(ex, self.provider)
            except requests.exceptions.RequestException as ex:
                # catastrophic error. bail.
                raise IngestApiError.apiRequestError(ex, self.provider)
            except Exception as error:
                traceback.print_exc()
                raise IngestApiError.apiGeneralError(error, self.provider)

            if response.status_code == 404:
                raise LookupError('Not found %s' % payload)

            break

        try:
            return etree.fromstring(response.content)  # workaround for http mock lib
        except UnicodeEncodeError as error:
            traceback.print_exc()
            raise IngestApiError.apiUnicodeError(error, self.provider)
        except ParseError as error:
            traceback.print_exc()
            raise IngestApiError.apiParseError(error, self.provider)
        except Exception as error:
            traceback.print_exc()
            raise IngestApiError.apiGeneralError(error, self.provider)
开发者ID:jerome-poisson,项目名称:superdesk-core,代码行数:56,代码来源:reuters.py

示例2: test_raise_apiParseError

# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiParseError [as 别名]
 def test_raise_apiParseError(self):
     with assert_raises(IngestApiError) as error_context:
         ex = Exception("Testing apiParseError")
         raise IngestApiError.apiParseError(ex, self.provider)
     exception = error_context.exception
     self.assertTrue(exception.code == 4005)
     self.assertTrue(exception.message == "API ingest xml parse error")
     self.assertIsNotNone(exception.system_exception)
     self.assertEqual(exception.system_exception.args[0], "Testing apiParseError")
     self.assertEqual(len(self.mock_logger_handler.messages['error']), 1)
     self.assertEqual(self.mock_logger_handler.messages['error'][0],
                      "IngestApiError Error 4005 - API ingest xml parse error: "
                      "Testing apiParseError on channel TestProvider")
开发者ID:ancafarcas,项目名称:superdesk-core,代码行数:15,代码来源:errors_test.py

示例3: _get_tree

# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiParseError [as 别名]
    def _get_tree(self, endpoint, payload=None):
        """
        Get xml response for given API endpoint and payload.
        :param: endpoint
        :type endpoint: str
        :param: payload
        :type payload: str
        """

        if payload is None:
            payload = {}

        payload['token'] = self._get_auth_token(self.provider, update=True)
        url = self._get_absolute_url(endpoint)

        try:
            response = requests.get(url, params=payload, timeout=15)
        except requests.exceptions.Timeout as ex:
            # Maybe set up for a retry, or continue in a retry loop
            raise IngestApiError.apiTimeoutError(ex, self.provider)
        except requests.exceptions.TooManyRedirects as ex:
            # Tell the user their URL was bad and try a different one
            raise IngestApiError.apiRedirectError(ex, self.provider)
        except requests.exceptions.RequestException as ex:
            # catastrophic error. bail.
            raise IngestApiError.apiRequestError(ex, self.provider)
        except Exception as error:
            traceback.print_exc()
            raise IngestApiError.apiGeneralError(error, self.provider)

        if response.status_code == 404:
            raise LookupError('Not found %s' % payload)

        try:
            return etree.fromstring(response.content)  # workaround for http mock lib
        except UnicodeEncodeError as error:
            traceback.print_exc()
            raise IngestApiError.apiUnicodeError(error, self.provider)
        except ParseError as error:
            traceback.print_exc()
            raise IngestApiError.apiParseError(error, self.provider)
        except Exception as error:
            traceback.print_exc()
            raise IngestApiError.apiGeneralError(error, self.provider)
开发者ID:actionless,项目名称:superdesk,代码行数:46,代码来源:reuters.py

示例4: get_tree

# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiParseError [as 别名]
    def get_tree(self, endpoint, payload=None):
        """Get xml response for given API endpoint and payload."""
        if payload is None:
            payload = {}
        payload['token'] = self.get_token()
        url = self.get_url(endpoint)

        try:
            response = requests.get(url, params=payload, timeout=21.0)
        except requests.exceptions.Timeout as ex:
            # Maybe set up for a retry, or continue in a retry loop
            raise IngestApiError.apiTimeoutError(ex, self.provider)
        except requests.exceptions.TooManyRedirects as ex:
            # Tell the user their URL was bad and try a different one
            raise IngestApiError.apiRedirectError(ex, self.provider)
        except requests.exceptions.RequestException as ex:
            # catastrophic error. bail.
            raise IngestApiError.apiRequestError(ex, self.provider)
        except Exception as error:
            traceback.print_exc()
            raise IngestApiError(error, self.provider)

        if response.status_code == 404:
            raise IngestApiError.apiNotFoundError(LookupError('Not found %s' % payload), self.provider)

        try:
            # workaround for httmock lib
            # return etree.fromstring(response.text.encode('utf-8'))
            return etree.fromstring(response.content)
        except UnicodeEncodeError as error:
            traceback.print_exc()
            raise IngestApiError.apiUnicodeError(error, self.provider)
        except ParseError as error:
            traceback.print_exc()
            raise IngestApiError.apiParseError(error, self.provider)
        except Exception as error:
            traceback.print_exc()
            raise IngestApiError(error, self.provider)
开发者ID:akintolga,项目名称:superdesk-server,代码行数:40,代码来源:reuters.py

示例5: ReutersIngestService

# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiParseError [as 别名]
from superdesk.utc import utcnow
from superdesk.etree import etree, ParseError
from superdesk.io import register_provider
from .newsml_2_0 import NewsMLTwoParser
from .reuters_token import get_token
from superdesk.errors import IngestApiError
from flask import current_app as app


PROVIDER = 'reuters'
errors = [IngestApiError.apiTimeoutError().get_error_description(),
          IngestApiError.apiRedirectError().get_error_description(),
          IngestApiError.apiRequestError().get_error_description(),
          IngestApiError.apiUnicodeError().get_error_description(),
          IngestApiError.apiParseError().get_error_description(),
          IngestApiError.apiGeneralError().get_error_description()]


class ReutersIngestService(IngestService):
    """Reuters ingest service."""

    DATE_FORMAT = '%Y.%m.%d.%H.%M'
    URL = 'http://rmb.reuters.com/rmd/rest/xml'
    token = None

    def __init__(self):
        self.parser = NewsMLTwoParser()

    def get_token(self):
        """Get reuters token once for an update run."""
开发者ID:Flowdeeps,项目名称:superdesk-1,代码行数:32,代码来源:reuters.py


注:本文中的superdesk.errors.IngestApiError.apiParseError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。