views:

262

answers:

4

When would someone use httplib and when urllib?

What are the differences?

I think I ready urllib uses httplib, I am planning to make an app that will need to make http request and so far I only used httplib.HTTPConnection in python for requests, and reading about urllib I see I can use that for request too, so whats the benefit of one or the other?

+3  A: 

urllib (particularly urllib2) handles many things by default or has appropriate libs to do so. For example, urllib2 will follow redirects automatically and you can use cookiejar to handle login scripts. These are all things you'd have to code yourself if you were using httplib.

Robus
Thats what I tought, thank you.
jahmax
In short, use neither. Use urllib2?
S.Lott
Kinda :P Just think of urllib2 as... well, urllib with a "2" for "twice as awesome" at the end.
Robus
A: 

If you're dealing solely with http/https and need access to HTTP specific stuff, use httplib.

For all other cases, use urllib2.

Matt Joiner
+1  A: 

urllib/urllib2 is built on top of httplib. It offers more features than writing to httplib directly.

Corey Goldberg
A: 

If you need highlevel stuff like Caching, Keep-Alive, Compression or Authentication you should take a look at google's pythhon httlip implementation.

http://code.google.com/p/httplib2/

optixx