小编jar*_*889的帖子

为什么请求响应对象__bool__检查200 <= status <400?

根据请求模块来源,该__bool__功能仅用于检查响应的状态代码是否在200到400之间.

Returns True if :attr:`status_code` is less than 400.
This attribute checks if the status code of the response is between
400 and 600 to see if there was a client error or a server error. If
the status code, is between 200 and 400, this will return True. This
is **not** a check to see if the response code is ``200 OK``.
Run Code Online (Sandbox Code Playgroud)

使用该__bool__函数使得下面的代码不能按预期工作:

def request_url(url):
    error_message = None
    try:
        r = …
Run Code Online (Sandbox Code Playgroud)

python python-requests

1
推荐指数
1
解决办法
1476
查看次数

标签 统计

python ×1

python-requests ×1