urllib urllib2 what is the difference ?

Discussion in 'Python' started by Chris Lyon, Jan 7, 2004.

  1. Chris Lyon

    Chris Lyon Guest

    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?
    Chris Lyon, Jan 7, 2004
    #1
    1. Advertising

  2. On 7 Jan 2004 04:30:34 -0800, (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).
    Terry Carroll, Jan 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Monty
    Replies:
    4
    Views:
    428
    Monty
    Mar 14, 2005
  2. Alex Stapleton
    Replies:
    2
    Views:
    328
    Fuzzyman
    Mar 14, 2005
  3. Alex Stapleton
    Replies:
    5
    Views:
    722
    Mike Meyer
    Mar 15, 2005
  4. Jonathan Gardner

    Asynchronous urllib (urllib+asyncore)?

    Jonathan Gardner, Feb 26, 2008, in forum: Python
    Replies:
    1
    Views:
    459
    Terry Jones
    Feb 27, 2008
  5. Chris McDonald
    Replies:
    0
    Views:
    272
    Chris McDonald
    Nov 1, 2010
Loading...

Share This Page