Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 455201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:20:48+00:00 2026-05-12T22:20:48+00:00

>>> import httplib >>> conn = httplib.HTTPConnection(www.google.com) >>> conn.request(HEAD, /index.html) >>> res = conn.getresponse()

  • 0
>>> import httplib
>>> conn = httplib.HTTPConnection("www.google.com")
>>> conn.request("HEAD", "/index.html")
>>> res = conn.getresponse()
>>> print res.status, res.reason
200 OK

This code will get the HTTP status code. However, notice that I split up “google.com” and “/index.html” on 2 lines.

And it’s confusing.

What if I want to find the status code of just a general URL???

http://mydomain.com/sunny/boo.avi
http://anotherdomain.com/podcast.mp3
http://anotherdomain.com/rss/fee.xml

Can’t I just stick the URL into it, and make it work?

Edit…I cannot use urllib, because I don’t want to downlaod the file

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:20:50+00:00Added an answer on May 12, 2026 at 10:20 pm

    Alternatively, if you expect that actually downloading the data is problematic and you really need the HEAD method, you could parse the URL using urlparse:

    >>> import httplib
    >>> import urlparse
    >>> url = "http://www.google.com/index.html"
    >>> (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(url)
    >>> conn = httplib.HTTPConnection(netloc)
    >>> conn.request("HEAD", urlparse.urlunparse(('', '', path, params, query, fragment))
    >>> res = conn.getresponse()
    >>> print res.status, res.reason
    302 Found
    

    And wrap this into a function taking the URL as an argument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

import httplib conn = httplib.HTTPConnection(head) conn.request(HEAD,tail) res = conn.getresponse() print res.status I am currently
import httplib conn = httplib.HTTPConnection(head) conn.request(HEAD,tail) res = conn.getresponse() I can get the res.status
Why isn't this simple Python code working? import urllib file = urllib.urlopen('http://www.google.com') print file.read()
i am trying this python script: import httplib import urllib conn = httplib.HTTPConnection(moodle.tau.ac.il) conn.request(POST
I can pull a any page from wikipedia with import httplib conn = httplib.HTTPConnection(en.wikipedia.org)
import httplib def httpCode(theurl): if theurl.startswith(http://): theurl = theurl[7:] head = theurl[:theurl.find('/')] tail =
import httplib2 from urllib import urlencode h = httplib2.Http() h.add_credentials('zackster@gmail.com', 'PassWord') data = dict(key=ThisIsMyApiKeyICopiedAndPastedIt)
import xlrd book = xlrd.open_workbook(File_1.xls) sheet = book.sheet_by_index(0) print sheet.row_values(0)[0] I am trying to
import xlwt import xlrd import os.path import os print os.path.abspath(os.curdir) #Create workbook and worksheet
TL/DR: import gc, sys print len(gc.get_objects()) # 4073 objects in memory # Attempt to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.