【问题标题】:request module in python library gives status code as 200 when the browser gives 404当浏览器给出 404 时,python 库中的请求模块给出状态码为 200
【发布时间】:2019-01-16 02:33:54
【问题描述】:

Broswer shows page not found but request module gives 200 as status code

In[23]:  requests.get("http://abc.us.gib.com/tool/cluster.jsp")
Out[23]: <Response [200]>
In[24]:  requests.get("http://abc.us.gib.com/tool/cluster.jsphttp://abc.us.gib.com/tool/cluster.jsp")
Out[24]: <Response [200]>

给定两个 URL,浏览器对第一个 URL 工作正常,但对第二个 URL 给出错误,但在使用 python 请求模块检查相同时,它给出 200 作为两者的状态码。 附上图片供参考。

您将无法打开该 URL,因为外部无法访问。

【问题讨论】:

标签: python python-requests http-status-code-404


【解决方案1】:

站点“http://abc.us.gib.com/tool/cluster.jsphttp://abc.us.gib.com/tool/cluster.jsp”返回错误的状态码。请求模块工作正常。您可以在浏览器中查看网站返回的状态码。

【讨论】:

  • 是的,请求模块返回的状态码是错误的,但你能告诉我为什么状态码给出错误的状态码吗?
  • 可能是由于设置了 User-Agent 或 cookie。您可以尝试更改用户代理并在请求中添加 cookie。无论您是从 python 还是从浏览器调用网站,对于网络服务器来说,它都应该是无法区分的。
猜你喜欢
  • 2015-12-05
  • 1970-01-01
  • 2021-11-22
  • 1970-01-01
  • 2016-08-24
  • 1970-01-01
  • 1970-01-01
  • 2017-06-04
  • 2021-06-25
相关资源
最近更新 更多