Python请求:缺少内容长度响应
Python请求不会返回我可以通过curl获得的内容长度头Python请求:缺少内容长度响应,python,python-3.x,get,python-requests,head,Python,Python 3.x,Get,Python Requests,Head,Python请求不会返回我可以通过curl获得的内容长度头 def get_头(url): response=requests.head(url) 返回response.headers 答复: {'Server': 'nginx/1.17.9', 'Date': 'Sun, 24 May 2020 19:09:02 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Connection': 'keep-alive', 'Vary': 'Acc
def get_头(url):
response=requests.head(url)
返回response.headers
答复:
{'Server': 'nginx/1.17.9', 'Date': 'Sun, 24 May 2020 19:09:02 GMT', 'Content-Type': 'text/html; charset=utf-8', 'Connection': 'keep-alive', 'Vary': 'Accept-Encoding', 'Access-Control-Allow-Origin': '*', 'Content-Disposition': 'inline; filename="introduction - Sia API Documentation.html"', 'Skynet-File-Metadata': '{"filename":"introduction - Sia API Documentation.html"}', 'Access-Control-Expose-Headers': 'skynet-file-metadata', 'Content-Encoding': 'gzip'}
我还尝试了requests.get,但也无法工作:
response=requests.get(url,stream=True)
如果查看返回的标题,您会注意到:
传输编码:分块
但是,如果使用httpbin比较发送的头,您可能会注意到请求也发送接受编码:gzip,deflate。如果移除该标题,例如
r=requests.head(url,headers={'Accept-Encoding':None})
然后得到内容长度标题
资料来源: