【问题标题】:Sometimes Python Requests module and wget HTTP responses contradicts curl/Chrome有时 Python 请求模块和 wget HTTP 响应与 curl/Chrome 相矛盾
【发布时间】:2013-07-13 01:14:03
【问题描述】:

在检查一组 URL 上的 HTTP 状态代码返回时,我偶尔会看到 Python 'requests' 模块和 linux curl 的结果之间存在差异。

此 URL http://www.dagoradiosound.info/site/ 使用“requests”和 wget 返回“404”,但使用 curl 和 chrome 浏览器返回“200”。

有人知道为什么我会得到这些矛盾的结果吗?

#Python
import requests
url = "http://www.dagoradiosound.info/site/"
r = requests.head(url)
r.status_code

#curl
curl -sL -w "%{http_code} %{url_effective}\\n" "http://www.dagoradiosound.info/site/" -o /dev/null

#wget
wget --spider "http://www.dagoradiosound.info/site/"

【问题讨论】:

    标签: http python-2.7 python-requests


    【解决方案1】:

    您使用requests 而不是GET 发送HEAD 请求。 请改用requests.get("http://www.dagoradiosound.info/site/")

    使用 curl -I "http://www.dagoradiosound.info/site/" 仅获取标头也会返回此特定 URL 的 404 状态。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-05
      • 2011-10-23
      • 2018-07-22
      • 2011-01-08
      • 2022-12-04
      • 2019-07-29
      • 1970-01-01
      相关资源
      最近更新 更多