G
gervaz
Hi all, can someone tell me why the read() function in the following
py3 code returns b''?
b''
Thanks,
Mattia
py3 code returns b''?
b''
Thanks,
Mattia
Hi all, can someone tell me why the read() function in the following
py3 code returns b''?
b''
You mean why does it return an empty byte sequence? Because the HEAD
method only requests the response headers, not the body, so the body
is empty. If you want to see the response body, use GET.
Cheers,
Ian
The fact is that I have a list of urls and I wanted to retrieve the
minimum necessary information in order to understand if the link is a
valid html page or e.g. a picture or something else. As far as I
understood here http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
the HEAD command is the one that let you do this. But it seems it
doesn't work.
Hi all, can someone tell me why the read() function in the following
py3 code returns b''
b''
Because there is no body in a HEAD request. What is useful are the
Content-Type, Content-Length, and etag headers.
Is r.getcode() == 200? That indicates a successful response; you
*always* much check the response code before interpreting the response.
Also I'm pretty sure that "HTTP 1.0" is wrong.
I decided to implement this solution:
class HeadRequest(urllib.request.Request):
def get_method(self):
return "HEAD"
Now I download the url using:
r = HeadRequest(url, None, self.headers)
c = urllib.request.urlopen(r)
but I don't know how to retrieve the request status (e.g. 200) as in
the previous examples with a different implementation...
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.