9

as we know, python has two built-in url lib:

  • urllib
  • urllib2

and a third-party lib:

  • urllib3

if my requirement is only to request a API by GET method, assume it return a JSON string.
which lib I should use? do they have some duplicated functions?
if the urllib can implement my require, but after if my requirements get more and more complicated, the urllib can not fit my function, I should import another lib at that time, but I really want to import only one lib, because I think import all of them can make me confused, I think the method between them are totally different.

so now I am confused which lib I should use, I prefer urllib3, I think it can fit my requirement all time, how do you think?

Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
Mathew P. Jones
  • 843
  • 1
  • 11
  • 20
  • 4
    python [requests](http://requests.readthedocs.org/en/latest/) is the best you can get for simple http requests – Alexander Zhukov Dec 09 '13 at 09:31
  • 1
    maybe this question has relation with:http://stackoverflow.com/questions/2018026/should-i-use-urllib-or-urllib2-or-requests – Mathew P. Jones Dec 09 '13 at 09:35
  • 4
    As the author of urllib3, I highly suggest going with either requests (which is built on top of urllib3) or straight-up urllib3. Requests has a higher-level friendlier interface that many people like, that's up to you. Thanks to urllib3, you get a lot of things for free like connection reusing and more. Full list here: https://github.com/shazow/urllib3#highlights – shazow Dec 09 '13 at 17:46

3 Answers3

10

As Alexander says in the comments, use requests. That's all you need.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
4

I don't really know what you want to do, but you should try with requests. It's simple and intuitive.

Zulu
  • 8,765
  • 9
  • 49
  • 56
1

Personally I avoid to use third-party library when possible, so I can reduce the dependencies' list and improve portability. urllib and urllib2 are not mutually exclusive and are often mixed in the same project.

smeso
  • 4,165
  • 18
  • 27