python - HEAD 请求在重定向时缺少内容类型 (301)
问题描述
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'}
解决方案
设置 allow_redirects=True 就可以了。我以为这是默认设置,猜不出来。
推荐阅读
- javascript - 与 django 一起使用时 html 模板的不良行为
- cordova - 离子 InAppBrowser 事件未触发
- python - 对输出文件 AZ 进行排序
- javascript - 尝试导入错误:“ApiRequests”未从“./ApiRequests”导出
- python-3.x - 如何通过 API 和 Python 代码从 Snowflake 数据库或 AWS S3 将数据导入 Salesforce 沙箱?
- unity3d - 如何将 Valve.VR.HmdMatrix34_t 转换为 UnityEngine.Transform
- apiconnect - API Connect 中 API 的 Swagger 文档链接
- python - 使用 keras 分词器预处理 keras 数据集
- javascript - JavaScript Regex 去除没有属性的 html 标签
- admob - 在提交给 Apple 认证团队进行审核之前,我是否应该更改 Admob 测试 ID?SwiftUI