根据请求模块的来源,该__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)