Python Requests模块显示Bash Curl的不同标头

时间:2018-09-18 16:50:38

标签: python-3.x curl python-requests response-headers

我试图避免使用子流程模块来调用CURL,所以决定使用Requests,因为我无法让pyCurl完成这项工作。

有人知道如何使用Curl和Requests模块获得相同的输出标头。

卷曲重击: $ curl -IL www.google.com

HTTP/1.1 200 OK
Date: Tue, 18 Sep 2018 16:44:47 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
P3P: CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Set-Cookie: 1P_JAR=2018-09-18-16; expires=Thu, 18-Oct-2018 16:44:47 GMT; path=/; domain=.google.com
Set-Cookie: NID=139=hc6K7Og18VjtIxTHeMvhej_jm_G5EAUSR-tMfqIDmx83gIEfjqbX_92rV-WF1ianUU6iyjVK9hKxPtwcwcDtQG0Oo3ZRukxgXos4EM5VeczmwJo_lpldglhSKGsMfjxQ; expires=Wed, 20-Mar-2019 16:44:47 GMT; path=/; domain=.google.com; HttpOnly
Transfer-Encoding: chunked
Accept-Ranges: none
Vary: Accept-Encoding

========

Python脚本: 导入请求

r = requests.get('https://www.google.com')
r2 = r.headers

for k, v in r2.items():
        print(k, v)

产生输出:

Content-Type text/html; charset=ISO-8859-1
Date Tue, 18 Sep 2018 16:46:20 GMT
Expires -1
Content-Encoding gzip
Transfer-Encoding chunked
P3P CP="This is not a P3P policy! See g.co/p3phelp for more info."
Server gws
X-XSS-Protection 1; mode=block
Alt-Svc quic=":443"; ma=2592000; v="44,43,39,35"
X-Frame-Options SAMEORIGIN
Set-Cookie 1P_JAR=2018-09-18-16; expires=Thu, 18-Oct-2018 16:46:20 GMT; path=/; domain=.google.com, NID=139=yDtVp2gF9ZjlcjW4AS9reicjPJU1AQvOP4kkH4xMvybeBz4z_B5uFQNMgjbNybiGH7UgpLQLgW4fA20icuCCaqlHztys6LyO9gViH22TGGVv8k_IBsZUNBP5ssvosZ2H; expires=Wed, 20-Mar-2019 16:46:20 GMT; path=/; domain=.google.com; HttpOnly
Cache-Control private, max-age=0

因此,当使用Requests Vary标头时,缺少HTTP版本和方法等...

0 个答案:

没有答案