Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/336.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python请求:缺少内容长度响应_Python_Python 3.x_Get_Python Requests_Head - Fatal编程技术网

Python请求:缺少内容长度响应

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

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': '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})

然后得到内容长度标题

资料来源: