Python http.HTTPStatus.SEE_OTHER Examples

The following are 4 code examples of http.HTTPStatus.SEE_OTHER(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module http.HTTPStatus , or try the search function .
Example #1
Source File: responses.py    From apidaora with MIT License 5 votes vote down vote up
def see_other(headers: Sequence[Header] = (), **kwargs: Any) -> Response:
    return Response(
        status=HTTPStatus.SEE_OTHER,
        headers=headers,
        content_type=None,
        body=None,
        ctx=kwargs,
    ) 
Example #2
Source File: responses.py    From apidaora with MIT License 5 votes vote down vote up
def make_see_other_response(
    headers: Optional[ASGIHeaders] = None,
) -> ASGIResponse:
    return make_response(
        None, HTTPStatus.SEE_OTHER, headers, SEE_OTHER_RESPONSE, None,
    ) 
Example #3
Source File: fake_requests.py    From cf-python-client with Apache License 2.0 5 votes vote down vote up
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) 
Example #4
Source File: client.py    From Hands-On-Application-Development-with-PyCharm with MIT License 4 votes vote down vote up
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