http headers - getting content-length using requests using get gives correct result but why not with the head? -
I am a little surprised, while I was trying to understand but by So the right approach should be to get the right material-length, if this is the URL redirect issue which seems to be that because I request
module.
& gt; & Gt; & Gt; Furl = 'http://www.downvids.net/downloads/07275feaf477cc0f5a7a67cba965594d5c83/' & gt; & Gt; & Gt; Resp = requests.get (feral, header = {'approved-encoding': 'detection'})> gt; & Gt; & Gt; Resp.headers ['Content-Length'] '7254371' & gt; & Gt; & Gt; Resp2 = requests.head (furl) & gt; & Gt; & Gt; Resp2.headers ['content-length'] '20'
requests.get
I think that by doing this, download the whole file to buffer It's been the length of the material from which !!! resp2.status_code
has given me the 302
a
request, request
set allow_redirects
on the wrong, by default; This is different from all other HTTP methods, where the redirection by default is on see document. By default,
The default request will display location redirection for all actions except the head
You can force the redirect to follow this
did :
resp2 = request.head (furl, allow_redirects = true)
Your GET follow redirect (the original URL to the https://scontent-b-ams.xx.fbcdn.net/hvideo-xpa1/v/t42.1790-2/1598692_10153946120225652_1024334852_n.mp4?oh=de27dad30979955f4e8fef28b85f9af9&oe=53D50345 < / Code>); Your
HEAD
was not requested.
The server for the head while doing a GET, but the RFC action should also mean that a server ignore that requirement if the implementation is too expensive or any other Due to the reason
You can always request a GET which is the body stream = true
:
resp = requests.get (furl, stream = true )
Comments
Post a Comment