本文整理汇总了Python中requests.codes.not_found方法的典型用法代码示例。如果您正苦于以下问题:Python codes.not_found方法的具体用法?Python codes.not_found怎么用?Python codes.not_found使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests.codes
的用法示例。
在下文中一共展示了codes.not_found方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _raise_response_exceptions
# 需要导入模块: from requests import codes [as 别名]
# 或者: from requests.codes import not_found [as 别名]
def _raise_response_exceptions(response):
"""Raise specific errors on some status codes."""
if not response.ok and 'www-authenticate' in response.headers:
msg = response.headers['www-authenticate']
if 'insufficient_scope' in msg:
raise OAuthInsufficientScope('insufficient_scope', response.url)
elif 'invalid_token' in msg:
raise OAuthInvalidToken('invalid_token', response.url)
else:
raise OAuthException(msg, response.url)
if response.status_code == codes.forbidden: # pylint: disable=E1101
raise Forbidden(_raw=response)
elif response.status_code == codes.not_found: # pylint: disable=E1101
raise NotFound(_raw=response)
else:
try:
response.raise_for_status() # These should all be directly mapped
except exceptions.HTTPError as exc:
raise HTTPException(_raw=exc.response)
示例2: _rest_get_hostconfigs
# 需要导入模块: from requests import codes [as 别名]
# 或者: from requests.codes import not_found [as 别名]
def _rest_get_hostconfigs(self):
try:
response = self.odl_rest_client.get()
response.raise_for_status()
hostconfigs = response.json()['hostconfigs']['hostconfig']
except exceptions.ConnectionError:
LOG.error("Cannot connect to the OpenDaylight Controller",
exc_info=True)
return None
except exceptions.HTTPError as e:
# restconf returns 404 on operation when there is no entry
if e.response.status_code == codes.not_found:
LOG.debug("Response code not_found (404)"
" treated as an empty list")
return []
LOG.warning("REST/GET odl hostconfig failed, ",
exc_info=True)
return None
except KeyError:
LOG.error("got invalid hostconfigs", exc_info=True)
return None
except Exception:
LOG.warning("REST/GET odl hostconfig failed, ",
exc_info=True)
return None
else:
if LOG.isEnabledFor(logging.DEBUG):
_hconfig_str = jsonutils.dumps(
response, sort_keys=True, indent=4, separators=(',', ': '))
LOG.debug("ODLPORTBINDING hostconfigs:\n%s", _hconfig_str)
return hostconfigs