Python urllib vs httplib?

When will someone use httplib and when will urllib?

What are the differences?

I think I'm ready, urllib uses httplib, I plan to make an application that will need to make an http request, and so far I have used httplib.HTTPConnection in python for requests and read about urllib. I see that I can use this to query too, so what is the use of this or that?

+47
python urllib
Jul 22 2018-10-22T00:
source share
6 answers

urllib (especially urllib2) handles many things by default or has the appropriate libraries for this. For example, urllib2 will be automatically redirected, and you can use cookiejar to process login scripts. This is all you would need to code yourself if you are using httplib.

+42
Jul 22 '10 at 2:00
source

I would like to say something about urllib , urllib2 , httplib and httplib2 .

The main difference between urllib* and httplib* is this:

httplib and httplib2 process the HTTP / HTTP request and response directly and give you more space to do your own work.

urllib and urllib2 are built on httplib, they are more abstract and powerful, but sometimes they will not fulfill your specified need for some HTTP-related operations.

And for httplib and httplib2 I would say that they are both HTTP client library . However, httplib2 much more efficient and has much more features than httplib .

Regarding urllib and urllib2 , enter a quote from this link :

urllib and urllib2 are both Python modules that are associated with URL requests but offer different functions. The two most significant differences are listed below:

  • urllib2 can accept a Request object to set headers for requesting a url, urllib only accepts a url. This means that you cannot mask your User Agent string, etc.
  • urllib provides a urlencode method that is used to generate GET request strings, urllib2 does not have such a function. This is one of the reasons urllib is often used with urllib2.

I would recommend my personal blog Httplib Httplib2 Urllib Urllib2-whats the Difference .

Hope this helps :-)

+16
Nov 14 '13 at 9:10
source

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

however, httplib gives you finer control over basic connections.

+9
Jul 22 2018-10-22T00:
source

If you are dealing only with http / https and you need access to specific HTTP data, use httplib.

For all other cases, use urllib2.

+6
Jul 22 2018-10-22T00:
source

If you need high-level content like Caching, Keep-Alive, Compression or Authentication, try httplib2

+5
Jul 22 '10 at 6:20
source

For those people who move things up to Py3 (and for some reason cannot or have not refactored to use awesome requests ), this is a good transition between versions:

 try: import http.client as httplib except ImportError: import httplib 

Works like in Python version sets.

+1
Nov 20 '15 at 13:50
source



All Articles