Skip to content

Instantly share code, notes, and snippets.

@lerouxb
Created October 26, 2010 08:46
Show Gist options
  • Select an option

  • Save lerouxb/646556 to your computer and use it in GitHub Desktop.

Select an option

Save lerouxb/646556 to your computer and use it in GitHub Desktop.
Do a HEAD request on a URL and print status and headers
#!/usr/bin/env python
import httplib
import sys
from urlparse import urlparse
def head(url):
r = urlparse(url)
conn = httplib.HTTPConnection(r.netloc)
pathquery = r.path
if r.query:
pathquery = pathquery + '?' + r.query
conn.request("HEAD", pathquery)
res = conn.getresponse()
print res.status, res.reason
for k, v in res.getheaders():
print k+': '+v
if __name__ == "__main__":
if len(sys.argv) == 2:
head(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment