By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,289 Members | 1,463 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,289 IT Pros & Developers. It's quick & easy.

urllib urllib2 what is the difference ?

P: n/a
Could somebody please explain the difference between these two modules
and explain why they are both required, and if there will ever be a
unification of them?
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On 7 Jan 2004 04:30:34 -0800, ch********@spritenote.co.uk (Chris Lyon)
wrote:
Could somebody please explain the difference between these two modules
and explain why they are both required, and if there will ever be a
unification of them?


The main difference for me is that urllib2.urlopen can accept as an
argument, not only a URL name, but an instance of a Request class. The
Request class allows you to specify headers in the URL request. This is
helpful, for example, if you are retrieving a URL from a site that takes
different actions based on, say, the referral URL or the name of your
"browser", both of which are specified in request headers.

urllib.urlopen can only take a url string, and doesn't allow you (as far
as I can tell) to specify headers.

Another difference is the whole build_opener stuff that urllib2 provides,
but I've never had occasion to use or try to understand that, so I'll
leave that to someone else to explain.

On the flip side, urllib implements some things (like urlretrieve) that
urllib2 does not have; so urllib2 is not just a stepped-up urllib. That's
probably the reason they're not unified, at least for now (I have no
insight on future features).
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.