HEAD请求在重定向上缺少内容类型(301)

时间:2019-11-23 05:26:37

标签: python python-requests

requests.head('http://randwalk.com/s/s16.pdf',timeout=1).headers

给我

{'date': 'Sat, 23 Nov 2019 05:08:07 GMT', 'location': 'https://randwalk.com/s/s16.pdf', 'Age': '862', 'Set-Cookie': 'crumb=BZlltCLt+KDBZWFjYTlkODk3NzJjMTY0OThkOGI0M2FhMjQyNWZk;Path=/', 'x-contextid': '5hfZYmvv/QLoMH3KZ', 'server': 'Squarespace'}

如果具有content-type字段会更好。

例如,如果我直接输入重定向URL

requests.head('https://static1.squarespace.com/static/4ff39269c4aaf3fdb14faa05/t/50e6153fe4b0b7c7226f31a9/1357255999121/s16.pdf',timeout=1).headers

我明白了

{'timing-allow-origin': '*', 'content-type': 'application/pdf', 'cache-control': 'public, max-age=94608000', 'pragma': 'cache', 'x-contextid': '03YpYLSg/2vS31Z4Q', 'server': 'Squarespace', 'Via': '1.1 varnish, 1.1 varnish', 'Content-Length': '3429468', 'Accept-Ranges': 'bytes', 'Date': 'Sat, 23 Nov 2019 05:24:44 GMT', 'Age': '79996', 'Connection': 'keep-alive', 'X-Served-By': 'cache-dfw18628-DFW, cache-tyo19924-TYO', 'X-Cache': 'HIT, HIT', 'X-Cache-Hits': '1, 1', 'X-Timer': 'S1574486684.023261,VS0,VE5', 'Vary': 'Accept-Encoding', 'Tracepoint': 'Fastly'}

1 个答案:

答案 0 :(得分:0)

设置     allow_redirects =真 做到了。 我以为这是默认设置,不要这么认为。

相关问题