Fully construct the headers download picture, the size of the downloaded picture is 0?

1. Use python3"s requests module to download pictures with a size of 0?
2. My original code is as follows:

url =" https://www.wifi588.net/2025d."
headers =
{"authority":"www.wifi588.net",
" method":"GET",
"path":"/2025d6f1c179018205f04027361f1a49.jpg",
" scheme":"https",
"accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng, / ;
"accept-encoding":"",
" accept-language":"zh-CN,zh;q=0.9",
"cache-control":"max-age=0",
" cookie":"__cfduid=db035e73b552e0770b0d8f80ec68f1ab91521898939",
"if-none-match":"f4ee63a404f4332cce122986030578f2",
" upgrade-insecure-requests":"1",
"user-agent":"Mozilla/5.0 (Windows NT 6.1; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36"
}
response = requests.get (url,headers=headers)
name = url.split ("/") [- 1]
file_name = "f:/pic/ {}" .format (name)
with open (file_name, "wb") as f:

f.write(response.content)
f.close()

this is the request header I opened with F12 in the browser as follows:

I have constructed headers, completely according to the request header of the browser, but there is still a problem with the downloaded data. I really can"t find a solution. Thank you.

Mar.04,2021

do not add the if-none-match header, this field is to determine whether the cache expires. If you add this, the server thinks that you have cached the resource locally, and if it does not expire, it will not reply to the resource. Instead, it will add the Etag field in the response header to tell you to take it from the local cache.

in addition, you are not recommended to use the accept field, or to specify unwanted MIME types in accept. Take your request as an example, you want to get a jpg image, and you have image/webp in your accept. If the server happens to support webp compression, it will return a webp image to you instead of the original jpg image.

Menu