1

在检查一堆 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/"
4

1 回答 1

3

您正在发送 HEAD 请求requests而不是 GET。试试requests.get("http://www.dagoradiosound.info/site/")吧。

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

于 2013-07-12T16:48:07.107 回答