本文整理汇总了Python中superdesk.errors.IngestApiError.apiURLError方法的典型用法代码示例。如果您正苦于以下问题:Python IngestApiError.apiURLError方法的具体用法?Python IngestApiError.apiURLError怎么用?Python IngestApiError.apiURLError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类superdesk.errors.IngestApiError
的用法示例。
在下文中一共展示了IngestApiError.apiURLError方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _fetch_data
# 需要导入模块: from superdesk.errors import IngestApiError [as 别名]
# 或者: from superdesk.errors.IngestApiError import apiURLError [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)