HTTPConncetion - HEAD request
Elias Fotinis
efotinis at yahoo.com
Sun Jun 19 09:21:32 EDT 2011
On Fri, 17 Jun 2011 20:53:39 +0300, gervaz <gervaz at gmail.com> wrote:
> 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...
Use c.getcode() to get the response code. When you're testing interactively, you might find printing the headers with "print c.headers" quite handy.
Don't forget to close the response (c.close()) when your script exits its experimental state.
More information about the Python-list
mailing list