Python 我应该选择哪个 urllib?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20467107/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Which urllib I should choose?
提问by Mathew P. Jones
as we know, python has two built-in url lib:
我们知道,python 有两个内置的 url 库:
urlliburllib2
urlliburllib2
and a third-party lib:
和第三方库:
urllib3
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 urllibcan implement my require, but after if my requirements get more and more complicated, the urllibcan 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.
如果我的要求只是通过 GET 方法请求 API,假设它返回一个 JSON 字符串。
我应该使用哪个库?他们有一些重复的功能吗?
如果urllib可以实现我的require,但是之后如果我的需求越来越复杂,urllib不能适应我的功能,我当时应该再导入一个库,但我真的只想导入一个库,因为我认为导入所有它们会让我感到困惑,我认为它们之间的方法完全不同。
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?
所以现在我很困惑我应该使用哪个库,我更喜欢urllib3,我认为它可以一直满足我的要求,你觉得如何?
采纳答案by Daniel Roseman
As Alexander says in the comments, use requests. That's all you need.
正如亚历山大在评论中所说,使用requests. 这就是你所需要的。
回答by Zulu
回答by smeso
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.
我个人尽可能避免使用第三方库,这样我可以减少依赖项的列表并提高可移植性。urllib 和 urllib2 并不相互排斥,经常混在同一个项目中。

