python中see一_Python HTTPStatus.SEE_OTHER属性代码示例

# 需要导入模块: 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值