简体   繁体   English

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

[英]HEAD request missing content-type on redirect (301)

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

gives me给我

{'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'}

It would be better if it had the content-type field.如果它有content-type字段会更好。

For example, if I put the redirect URL straight in例如,如果我将重定向 URL 直接放入

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

I get我得到

{'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'}

Setting allow_redirects=True did the trick.设置 allow_redirects=True 可以解决问题。 I thought that was the default, guess not.我认为这是默认设置,猜猜不是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM