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 881697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T12:18:16+00:00 2026-05-15T12:18:16+00:00

Whenever looking at API libraries for Python, there seems to be about half of

  • 0

Whenever looking at API libraries for Python, there seems to be about half of them simply using:

response = urllib2.urlopen('https://www.example.com/api', data)

and about half using:

connection = httplib.HTTPSConnection('www.example.com/api')
# ... rest omitted for simplicity

I tend to think the second version is “cooler” (I’m biased towards a more OO approach to most things).

Is there a benefit or reason for using one over the other. Or, am I missing something along the way. I would suspect that urllib2.urlopen uses HTTPSConnection in its implementation, so perhaps one is simply less coding on my behalf. Whichever way, I’d love some feedback. Thanks.

  • 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-15T12:18:17+00:00Added an answer on May 15, 2026 at 12:18 pm

    Yep, urllib2 uses HTTPSConnection (or whatever kind of connection is appropriate for the protocol) in its implementation. It’s basically just a shortcut to do the most common thing people do with httplib.

    urllib2 also has some code to handle things like redirects and authentication requests, all stuff you might have to code manually if you were doing it with plain httplib.

    EDIT: In response to Michael’s comment, if you were wondering about object vs. data… it sort of depends on what you’re going to do with it. If you need the connection object (e.g. to do something special with it, maybe a keepalive connection), then sure, go ahead and use the httplib way and return the connection object. But if you’re just trying to get the data, just get the data and return it. If you like OOP, know that everything in Python technically is an object; what you get from urllib2.urlopen is a file-like object which has methods to retrieve its value as a string object or as a list of lines (also string objects). I think most Python programmers would consider it a waste of effort to use httplib in the latter case.

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

Sidebar

Related Questions

Whenever I ask people about the difference between an API and a library, I
I'm looking for the following solution in PHP. Whenever a user clicks on a
Whenever I try installing anything using gem, I get this error - murtaza@murtaza-dev:~$ sudo
Something I don't enjoy about programming is learning a new API. For example, right
I am looking since yesterday to fix this problem, I know there are plenty
Looking through the achievement list for Visual Studio 2010, it says that there is
I'm developing a RESTful API for a client. The problem is, he's using a
I've built a timeline app, using the graph API to query the posts on
I am looking for a way to bind to an event whenever the text
Whenever a dialog appears and there is no attached handler, watin auto closes the

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.