Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change from urllib to requests #4

Open
anandghegde opened this issue May 15, 2012 · 1 comment
Open

change from urllib to requests #4

anandghegde opened this issue May 15, 2012 · 1 comment

Comments

@anandghegde
Copy link
Contributor

I say we remove urllib and urllib2 and use requests instead.

It has many advantages

check it out here

http://docs.python-requests.org/en/latest/index.html

@boyska
Copy link
Owner

boyska commented May 16, 2012

Well, it sure is an impressive library. But speaking of our real needs, I have to say that we mostly do GET requests, building search query. This usually boils down to these 3 lines:

search = "%(artist)s %(title)s" % song_metadata
query = urllib.urlencode({'q': search})
url = 'http://www.lyricsite.org/search.php?%s' % query
page = lxml.html.parse(urllib2.urlopen(url))

How would this become using requests?

search = "%(artist)s %(title)s" % song_metadata
r = requests.get('http://www.lyricsite.org/search.php', {'q': search})
page = lxml.html.parse(r.raw)

Well, one line saved. Just a bit more elegant, but the difference is not that much

My opinion is that, on "basic" GET we just use urllib and urllib2.
If, however, you feel that sometimes urllib is just too boring to use, don't be afraid using requests: it will become a dependency for just that retriever, so it's not a big problem.

Am I missing some point about requests advantages?
Just my 2 cents, feel free to say me I'm just wrong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants