本文整理匯總了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