How do you send a HEAD HTTP request in Python 2? -
what i'm trying here headers of given url can determine mime type. want able see if http://somedomain/foo/
return html document or jpeg image example. thus, need figure out how send head request can read mime type without having download content. know of easy way of doing this?
edit: answer works, nowadays should use requests library mentioned other answers below.
use httplib.
>>> import httplib >>> conn = httplib.httpconnection("www.google.com") >>> conn.request("head", "/index.html") >>> res = conn.getresponse() >>> print res.status, res.reason 200 ok >>> print res.getheaders() [('content-length', '0'), ('expires', '-1'), ('server', 'gws'), ('cache-control', 'private, max-age=0'), ('date', 'sat, 20 sep 2008 06:43:36 gmt'), ('content-type', 'text/html; charset=iso-8859-1')]
there's getheader(name)
specific header.
Comments
Post a Comment