General Question

richardhenry's avatar

Why do the majority of Python packages use urllib2 instead of httplib?

Asked by richardhenry (12692points) April 9th, 2010
3 responses
“Great Question” (1points)

httplib is much better documented and seems so much better put together than urllib2. Am I missing something? The majority of applications and Python packages seem to favor urllib2 over httplib, and I don’t understand why.

Just compare the documentation for the two:
– httplib: http://docs.python.org/library/httplib.html
– urllib2: http://docs.python.org/library/urllib2.html

Is there a reason why a lot of people seem to favor the latter?

Observing members: 0
Composing members: 0

Answers

andrew's avatar

urllib2 is closer to curl. It’s closer to a real client—and for many of us, makes much more sense than doing 4 or 5 steps to request an url and read the response.

httplib is a lower level library. As it says in the docs: “It is normally not used directly — the module urllib uses it to handle URLs that use HTTP and HTTPS.”

noyesa's avatar

Because Python folks love abstraction, and so do I. It’s a lot easier to deal with, and just like @andrew said it’s a lot closer to a real client like curl, which is mostly second nature for me because I mostly use Unix and it’s hard to avoid when you’re programming with PHP.

richardhenry's avatar

Okay, I guess I’m mostly just complaining about how messily the abstraction is implemented in urllib2. Timeouts aren’t always handled correctly (although they seem to be with httplib), and so many third-party libraries that I’ve seen utilizing it don’t properly catch the exceptions it raises (possibly because they’re buried away in the middle of the document instead of having a heading and section of their own; like most other docs).

Answer this question

Login

or

Join

to answer.

Mobile | Desktop


Send Feedback   

`