本文整理匯總了Python中http.HTTPStatus.SEE_OTHER屬性的典型用法代碼示例。如果您正苦於以下問題:Python HTTPStatus.SEE_OTHER屬性的具體用法?Python HTTPStatus.SEE_OTHER怎麽用?Python HTTPStatus.SEE_OTHER使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類http.HTTPStatus
的用法示例。
在下文中一共展示了HTTPStatus.SEE_OTHER屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: see_other
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SEE_OTHER [as 別名]
def see_other(headers: Sequence[Header] = (), **kwargs: Any) -> Response:
return Response(
status=HTTPStatus.SEE_OTHER,
headers=headers,
content_type=None,
body=None,
ctx=kwargs,
)
示例2: make_see_other_response
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SEE_OTHER [as 別名]
def make_see_other_response(
headers: Optional[ASGIHeaders] = None,
) -> ASGIResponse:
return make_response(
None, HTTPStatus.SEE_OTHER, headers, SEE_OTHER_RESPONSE, None,
)
示例3: __init__
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SEE_OTHER [as 別名]
def __init__(self, url: str, status_code: int, text: str, headers: dict = None):
self.status_code = status_code
self.url = url
self.text = text
self.headers = dict()
self.is_redirect = status_code == HTTPStatus.SEE_OTHER
if headers is not None:
self.headers.update(headers)
示例4: _handle_redirects
# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SEE_OTHER [as 別名]
def _handle_redirects(self, response, data='', content_type='', **extra):
"""
Follow any redirects by requesting responses from the server using GET.
"""
response.redirect_chain = []
redirect_status_codes = (
HTTPStatus.MOVED_PERMANENTLY,
HTTPStatus.FOUND,
HTTPStatus.SEE_OTHER,
HTTPStatus.TEMPORARY_REDIRECT,
HTTPStatus.PERMANENT_REDIRECT,
)
while response.status_code in redirect_status_codes:
response_url = response.url
redirect_chain = response.redirect_chain
redirect_chain.append((response_url, response.status_code))
url = urlsplit(response_url)
if url.scheme:
extra['wsgi.url_scheme'] = url.scheme
if url.hostname:
extra['SERVER_NAME'] = url.hostname
if url.port:
extra['SERVER_PORT'] = str(url.port)
# Prepend the request path to handle relative path redirects
path = url.path
if not path.startswith('/'):
path = urljoin(response.request['PATH_INFO'], path)
if response.status_code in (HTTPStatus.TEMPORARY_REDIRECT, HTTPStatus.PERMANENT_REDIRECT):
# Preserve request method post-redirect for 307/308 responses.
request_method = getattr(self, response.request['REQUEST_METHOD'].lower())
else:
request_method = self.get
data = QueryDict(url.query)
content_type = None
response = request_method(path, data=data, content_type=content_type, follow=False, **extra)
response.redirect_chain = redirect_chain
if redirect_chain[-1] in redirect_chain[:-1]:
# Check that we're not redirecting to somewhere we've already
# been to, to prevent loops.
raise RedirectCycleError("Redirect loop detected.", last_response=response)
if len(redirect_chain) > 20:
# Such a lengthy chain likely also means a loop, but one with
# a growing path, changing view, or changing query argument;
# 20 is the value of "network.http.redirection-limit" from Firefox.
raise RedirectCycleError("Too many redirects.", last_response=response)
return response