What is the difference between urllib and urllib2 modules of python?

Source: Internet
Author: User

What is the difference between urllib and urllib2 modules of python?

You might be intrigued by the existence of two separate URL modules in Python-UrllibAndUrllib2. Even more intriguing: they are not alternatives for each other. So what is the differenceUrllibAndUrllib2, And do we need them both?

UrllibAndUrllib2Are both Python modules that do URL request related stuff but offer different functionalities. Their two most significant differences are listed below:

 

    • Urllib2Can acceptRequestObject To set the headers for a URL request,UrllibAccepts only a URL. That means, you cannot masquerade your user agent string etc.
    • UrllibProvidesUrlencodeMethod which is used for the generation of get query strings,Urllib2Doesn't have such a function. This is one of the reasons whyUrllibIs often used alongUrllib2.

For other differencesUrllibAndUrllib2Refer to their documentations, the links are given in the references section.

 

Tip: If you are planning to do HTTP stuff only, check out httplib2, it is much better than httplib or urllib or urllib2.

Exercise

    1. What is user agent?
    2. What is the difference between get and POST request methods?
    3. What is HTTP?

References

    1. Urllib
    2. Urllib2

Original article: http://www.hacksparrow.com/python-difference-between-urllib-and-urllib2.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.