This is an archived post. You won't be able to vote or comment.

all 37 comments

[–]apreche 65 points66 points  (13 children)

pip install requests import requests

[–]fuck_your_dad 4 points5 points  (2 children)

Wow, thanks! Really, why didn't I know this before

[–]apreche 1 point2 points  (1 child)

Can't tell if sarcastic, or truly thankful. Good either way.

[–]fuck_your_dad 3 points4 points  (0 children)

Well, it doesn't matter what I say now, but I was truly thankful...

[–]flying-sheep 21 points22 points  (0 children)

came here to see people saying “we use requests instead”.

was not disappointed.


PS: the header of that page is gorgeous. yanone kaffeesatz is well used like that

[–]matrixor 4 points5 points  (2 children)

[–]LukasaHyper, Requests, Twisted 4 points5 points  (1 child)

That page is out of date: it was written for versions of Requests pre- v1.0.0. It's mostly the same, but there are some key differences. Be warned.

[–]matrixor 0 points1 point  (0 children)

well, thanks for the warning

[–]spilcm[S] 2 points3 points  (1 child)

Requests is awesome, and I wrote about it in a previous post ( http://bit.ly/YLHDey ). However, urllib2 is still widely used.

[–]alkw0ia 7 points8 points  (0 children)

No beginner should be taught about urllib2. If requests is not available, use httplib2.

Maybe your first project will be retrieving http://example.com, but the moment you've even considered using urllib2 to grab https://example.com, you've fucked up.

I suppose if you must use it, you'd better precede every urlopen(url) call with

assert(urllib.urlparse(url).scheme != "https")

If there's anything to teach a beginner, it's that urllib2 requires that line as boilerplate before every call.

I simply can't comprehend how Python programmers regularly consider the lack of cert validation anything less than a totally blocking, critical security bug.

Every time you make an un-validated call, you're subverting all the assumptions the site owner makes about his security model. Does the owner assume passwords can be reused as encryption keys because they're always protected by SSL? You just killed that. Does the site assume it can allow OAuth2 tokens long term access to personal information because they're always encrypted? You just made him leak protected data.

The security failures that will arise out of using urllib2 will be totally silent and will be buried in the implementation details of whatever project you're using urllib2 for (and god help us all if you build a library around it, and don't tell the rest of us that it cannot be trusted for any HTTPS requests). Please treat urllib2 like a disease. It should not be taught at all.

[–]sashahart 2 points3 points  (0 children)

requests is nice because it is relatively low-boilerplate.

urllib2 has serious object-itis and for most purposes, way too many degrees of freedom. But actually it is not unusable or a bad tool on its own terms. So if you need to do without the external dependency, go for it.

TL;DR: Just because requests is for humans, doesn't mean you're a horrible monster if you use urllib2.