本文整理汇总了Python中superdesk.errors.IngestApiError.apiNotFoundError方法的典型用法代码示例。如果您正苦于以下问题:Python IngestApiError.apiNotFoundError方法的具体用法?Python IngestApiError.apiNotFoundError怎么用?Python IngestApiError.apiNotFoundError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类superdesk.errors.IngestApiError
的用法示例。
在下文中一共展示了IngestApiError.apiNotFoundError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _fetch_data
# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiNotFoundError [as 别名]
def _fetch_data(self, config, provider):
"""Fetch the latest feed data.
:param dict config: RSS resource configuration
:param provider: data provider instance, needed as an argument when
raising ingest errors
:return: fetched RSS data
:rtype: str
:raises IngestApiError: if fetching data fails for any reason
(e.g. authentication error, resource not found, etc.)
"""
url = config["url"]
if config.get("auth_required", False):
auth = (config.get("username"), config.get("password"))
else:
auth = None
response = requests.get(url, auth=auth)
if response.ok:
return response.content
else:
if response.status_code in (401, 403):
raise IngestApiError.apiAuthError(Exception(response.reason), provider)
elif response.status_code == 404:
raise IngestApiError.apiNotFoundError(Exception(response.reason), provider)
else:
raise IngestApiError.apiGeneralError(Exception(response.reason), provider)
示例2: _fetch_data
# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiNotFoundError [as 别名]
def _fetch_data(self, config, provider):
url = config['url']
api_key = config['api_key']
last_update = provider.get('last_updated', utcfromtimestamp(0)).strftime('%Y-%m-%dT%H:%M:%S')
# Results are pagified so we'll read this many at a time
offset_jump = 10
params = {'start': last_update, 'limit': offset_jump}
headers = {'apikey': api_key}
items = []
offset = 0
while True:
params['offset'] = offset
try:
response = requests.get(url, params=params, headers=headers, timeout=30)
except requests.exceptions.ConnectionError as err:
raise IngestApiError.apiConnectionError(exception=err)
if response.ok:
# The total number of results are given to us in json, get them
# via a regex to read the field so we don't have to convert the
# whole thing to json pointlessly
item_ident = re.search('\"total\": *[0-9]*', response.text).group()
results_str = re.search('[0-9]+', item_ident).group()
if results_str is None:
raise IngestApiError.apiGeneralError(
Exception(response.text), provider)
num_results = int(results_str)
if num_results > 0:
items.append(response.text)
if offset >= num_results:
return items
offset += offset_jump
else:
if re.match('Error: No API Key provided', response.text):
raise IngestApiError.apiAuthError(
Exception(response.text), provider)
elif response.status_code == 404:
raise IngestApiError.apiNotFoundError(
Exception(response.reason), provider)
else:
raise IngestApiError.apiGeneralError(
Exception(response.reason), provider)
return items
示例3: test_raise_apiNotFoundError
# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiNotFoundError [as 别名]
def test_raise_apiNotFoundError(self):
with assert_raises(IngestApiError) as error_context:
ex = Exception("Testing apiNotFoundError")
raise IngestApiError.apiNotFoundError(ex, self.provider)
exception = error_context.exception
self.assertTrue(exception.code == 4006)
self.assertTrue(exception.message == "API service not found(404) error")
self.assertIsNotNone(exception.system_exception)
self.assertEqual(exception.system_exception.args[0], "Testing apiNotFoundError")
self.assertEqual(len(self.mock_logger_handler.messages['error']), 1)
self.assertEqual(self.mock_logger_handler.messages['error'][0],
"IngestApiError Error 4006 - API service not found(404) error: "
"Testing apiNotFoundError on channel TestProvider")
示例4: _fetch_data
# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiNotFoundError [as 别名]
def _fetch_data(self, config, provider):
"""Fetch the latest feed data.
:param dict config: RSS resource configuration
:param provider: data provider instance, needed as an argument when
raising ingest errors
:return: fetched RSS data
:rtype: str
:raises IngestApiError: if fetching data fails for any reason
(e.g. authentication error, resource not found, etc.)
"""
url = config['url']
if config.get('auth_required', False):
auth = (config.get('username'), config.get('password'))
self.auth_info = {
'username': config.get('username', ''),
'password': config.get('password', '')
}
else:
auth = None
try:
response = requests.get(url, auth=auth, timeout=30)
except requests.exceptions.ConnectionError as err:
raise IngestApiError.apiConnectionError(exception=err, provider=provider)
except requests.exceptions.RequestException as err:
raise IngestApiError.apiURLError(exception=err, provider=provider)
if response.ok:
return response.content
else:
if response.status_code in (401, 403):
raise IngestApiError.apiAuthError(
Exception(response.reason), provider)
elif response.status_code == 404:
raise IngestApiError.apiNotFoundError(
Exception(response.reason), provider)
else:
raise IngestApiError.apiGeneralError(
Exception(response.reason), provider)
示例5: _test
# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiNotFoundError [as 别名]
def _test(self, provider):
config = provider.get('config', {})
url = config['url']
api_key = config['api_key']
# limit the data to a single article and filter out all article fields
# to save bandwidth
params = {'limit': 1, 'fields': 'id'}
headers = {'apikey': api_key}
try:
response = requests.get(url, params=params, headers=headers, timeout=30)
except requests.exceptions.ConnectionError as err:
raise IngestApiError.apiConnectionError(exception=err)
if not response.ok:
if response.status_code == 404:
raise IngestApiError.apiNotFoundError(
Exception(response.reason), provider)
else:
raise IngestApiError.apiGeneralError(
Exception(response.reason), provider)
示例6: get_tree
# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiNotFoundError [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)
示例7: RssIngestService
# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiNotFoundError [as 别名]
from superdesk.errors import IngestApiError, ParserError
from superdesk.io import register_provider
from superdesk.io.ingest_service import IngestService
from superdesk.utils import merge_dicts
from urllib.parse import quote as urlquote, urlsplit, urlunsplit
PROVIDER = "rss"
utcfromtimestamp = datetime.utcfromtimestamp
errors = [
IngestApiError.apiAuthError().get_error_description(),
IngestApiError.apiNotFoundError().get_error_description(),
IngestApiError.apiGeneralError().get_error_description(),
ParserError.parseMessageError().get_error_description(),
]
class RssIngestService(IngestService):
"""Ingest service for providing feeds received in RSS 2.0 format.
(NOTE: it should also work with other syndicated feeds formats, too, since
the underlying parser supports them, but for our needs RSS 2.0 is assumed)
"""
ItemField = namedtuple("ItemField", ["name", "name_in_data", "type"])
item_fields = [