Which urllib I should choose?
Solution 1
As Alexander says in the comments, use requests
. That's all you need.
Solution 2
I don't really know what you want to do, but you should try with requests
. It's simple and intuitive.
Solution 3
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.
Mathew P. Jones
I am Xiang Zhuyuan(aka Matt), a software engineer, live in Tokyo, JP. I am working as a senior engineer for an EC company. I am familiar with a few programming languages, such as Python, Ruby, and Java. I am experienced to use those technical stack to develop scaled project, not only the back-end service, but also the front-end services, to be a full-stack developer.
Updated on July 12, 2022Comments
-
Mathew P. Jones almost 2 years
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 theurllib
can implement my require, but after if my requirements get more and more complicated, theurllib
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? -
Mathew P. Jones over 10 yearsless import, consistent style methods
-
Mathew P. Jones over 10 yearsyes, thanks. I read requests docs, it base on urllib3, I think I can use it to finish almost my jobs