小编Ale*_*ser的帖子

Python URL Gets 方法返回状态 200,即使它是 404

我使用以下代码返回 URL 的状态

import requests
answer = requests.get('http://www.website.com')
answer.status_code
>>>200
Run Code Online (Sandbox Code Playgroud)

这给了我 200。

但是,网站应该返回 404。

answer.content
>>>b'<html><head>\r\n<title>404 Not Found</title>\r\n</head><body>\r\n<h1>Not   Found</h1>\r\n<p>The requested URL index.php was not found on this server.</p>\r\n<hr>\r\n<address>Apache/2.2.22 (Linux) Server at Port <small onclick="document.getElementById(\'login\').style.display = \'block\';">80</small></address>\r\n</body></html><div id="login" style="display:none;"><pre align=center><form method=post>Password: <input type=password name=pass><input type=submit value=\'>>\'></form></pre></div>'
Run Code Online (Sandbox Code Playgroud)

有人可以告诉我差异源自何处以及如何解决此问题以获得answer.status_code = 404 作为结果而不是 200?我无法直接访问服务器,但我可以询问管理员。

谢谢你!

python url request http-status-codes

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

标签 统计

http-status-codes ×1

python ×1

request ×1

url ×1