What are the differences between the urllib, urllib2, urllib3 and requests module?

后端 未结 11 2449
隐瞒了意图╮
隐瞒了意图╮ 2020-11-22 04:19

In Python, what are the differences between the urllib, urllib2, urllib3 and requests modules? Why are there three? They seem to do the same thing...

11条回答
  •  轮回少年
    2020-11-22 04:44

    This is my understanding of what the relations are between the various "urllibs":

    In the Python 2 standard library there exist two HTTP libraries side-by-side. Despite the similar name, they are unrelated: they have a different design and a different implementation.

    • urllib was the original Python HTTP client, added to the standard library in Python 1.2.
    • urllib2 was a more capable HTTP library, added in Python 1.6, intended to be eventually a replacement for urllib.

    The Python 3 standard library has a new urllib, that is a merged/refactored/rewritten version of those two packages.

    urllib3 is a third-party package. Despite the name, it is unrelated to the standard library packages, and there is no intention to include it in the standard library in the future.

    Finally, requests internally uses urllib3, but it aims for an easier-to-use API.

提交回复
热议问题