urllib2 for HTTPS/SSL

Discussion in 'Python' started by Kylotan, Jul 8, 2003.

  1. Kylotan

    Kylotan Guest

    The documentation on this module doesn't seem very clear to me...
    there's an 'HTTPSHandler' object documented, but it just lists the
    "https_open" function without giving an example of its use. And the
    urllib2 examples page shows a totally different way to create an HTTPS
    connection (just by making a Request object). There is a lot of talk
    about deriving new classes, but is that necessary if I just want to
    make HTTPS GET requests?

    I have no idea how (or if) to use the 'HTTPSHandler' object, or what
    the correct way for me to request an SSL connection is. Does anybody
    have any hints? And additionally, is there any chance of the official
    documentation on this useful-looking module being improved?

    K.
    Kylotan, Jul 8, 2003
    #1
    1. Advertising

  2. On Tue, 2003-07-08 at 06:33, Kylotan wrote:
    > The documentation on this module doesn't seem very clear to me...
    > there's an 'HTTPSHandler' object documented, but it just lists the
    > "https_open" function without giving an example of its use. And the
    > urllib2 examples page shows a totally different way to create an HTTPS
    > connection (just by making a Request object). There is a lot of talk
    > about deriving new classes, but is that necessary if I just want to
    > make HTTPS GET requests?
    >
    > I have no idea how (or if) to use the 'HTTPSHandler' object, or what
    > the correct way for me to request an SSL connection is. Does anybody
    > have any hints? And additionally, is there any chance of the official
    > documentation on this useful-looking module being improved?


    Unless I misunderstand your intent, you don't need to use the Handler
    object directly. HTTPS support is provided automatically, so long as
    your local Python has SSL support. (It should.)

    Here's an example:

    f = urllib2.urlopen("https://sf.net/")
    buf = f.read()
    f.close()

    The module is included in the standard library docs. They are brief,
    but do provide some examples:

    http://www.python.org/dev/doc/devel/lib/urllib2-examples.html

    Jeremy
    Jeremy Hylton, Jul 8, 2003
    #2
    1. Advertising

  3. > [Kylotan]
    > ........................Is there any chance of the official
    > documentation on this useful-looking module being improved?


    It is one of the biggest problems with Python that not enough people
    like to write good documentation about how to use the Python Standard
    Library. I think the best documentation for you is the book "Python
    Standard Library" (PSL) by Fredrik Lundh with its nice examples (could
    use even more!); but some bonehead at O'Reilly made the decision to
    publish "Python in a Nutshell" and "Python Cookbook" instead of the
    2nd edition of PSL. But these have bad example code and the English
    feels bad, not as bad as my written English perhaps but not a pleasure
    to read either.

    Many Python modules have a class based design and class based
    frameworks need a detailed description and especially examples how to
    use those classes. That will also force the designers to give a
    *motivation* for the class-based design. Answer questions like "Why
    do I want users of this module to subclass my Application class?
    Would it not be easier for them to supply just a list of functions
    with a clear description of input and output?". To my opinion there
    are just too much class based designs, like for example that Twisted
    thing: too much use of OO and inheritance makes it hard to understand
    and often leaves the user with the question "But why...". It would
    take a *LOT* of documentation to make up for the design decisions
    there.

    I am not against OO, it has its virtues; I am against overusing OO.
    And especially against class-based designs with poor documentation
    lacking motivation.


    --
    Python is an excellent language for learning object orientation. (It
    also happens to be my favorite OO scripting language.)
    -- Sriram Srinivasan, _Advanced Perl Programming_
    Will Stuyvesant, Jul 8, 2003
    #3
  4. Kylotan

    Kylotan Guest

    Jeremy Hylton <> wrote in message news:<>...
    > On Tue, 2003-07-08 at 06:33, Kylotan wrote:
    > > I have no idea how (or if) to use the 'HTTPSHandler' object, or what
    > > the correct way for me to request an SSL connection is. Does anybody
    > > have any hints? And additionally, is there any chance of the official
    > > documentation on this useful-looking module being improved?

    >
    > Unless I misunderstand your intent, you don't need to use the Handler
    > object directly. HTTPS support is provided automatically, so long as
    > your local Python has SSL support. (It should.)


    Ok, so what you're saying is that the stuff documented in:
    "Python Library Reference - 11.5.14 HTTPSHandler Objects"
    is purely an implementational detail? In other words, they're
    specifying examples of Handler classes in case you wanted to see how
    to write one yourself, but to use the urllib2 library normally you'd
    never need to really know this?

    I'm guessing the OpenerDirector object tries the URL with each
    BaseHandler-derived object to see which one should handle it.

    Thanks,

    K.
    Kylotan, Jul 9, 2003
    #4
  5. Kylotan

    Kylotan Guest

    (Will Stuyvesant) wrote in message news:<>...
    > > [Kylotan]
    > > ........................Is there any chance of the official
    > > documentation on this useful-looking module being improved?

    >
    > It is one of the biggest problems with Python that not enough people
    > like to write good documentation about how to use the Python Standard
    > Library.


    It's a shame about the documentation, but then this stuff is generally
    provided for free and so I think we're all grateful that it exists at
    all, documented or not. :) Maybe it would be beneficial for the
    official online documentation to allow users to add annotations in
    much the same way that the PHP and SDL docs do? Then not only people
    can get more use out of the docs, but the official maintainers of each
    module can easily see about integrating any useful errata or examples
    into their source documentation.

    K.
    Kylotan, Jul 9, 2003
    #5
  6. On Wed, 2003-07-09 at 05:29, Kylotan wrote:
    > Jeremy Hylton <> wrote in message news:<>...
    > > On Tue, 2003-07-08 at 06:33, Kylotan wrote:
    > > > I have no idea how (or if) to use the 'HTTPSHandler' object, or what
    > > > the correct way for me to request an SSL connection is. Does anybody
    > > > have any hints? And additionally, is there any chance of the official
    > > > documentation on this useful-looking module being improved?

    > >
    > > Unless I misunderstand your intent, you don't need to use the Handler
    > > object directly. HTTPS support is provided automatically, so long as
    > > your local Python has SSL support. (It should.)

    >
    > Ok, so what you're saying is that the stuff documented in:
    > "Python Library Reference - 11.5.14 HTTPSHandler Objects"
    > is purely an implementational detail? In other words, they're
    > specifying examples of Handler classes in case you wanted to see how
    > to write one yourself, but to use the urllib2 library normally you'd
    > never need to really know this?


    urllib2 provides a framework for writing custom handlers. If you want
    to create your own handlers or an opener with a custom set of handlers,
    this documentation may be helpful.

    > I'm guessing the OpenerDirector object tries the URL with each
    > BaseHandler-derived object to see which one should handle it.


    That's about right. Most of the handlers are registered for particular
    protocols. So the opener knows to use the HTTPSHandler for https://
    requests.

    Jeremy
    Jeremy Hylton, Jul 9, 2003
    #6
    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. Grant Edwards

    Why is ClientCookie/urllib2 using https?

    Grant Edwards, Sep 24, 2003, in forum: Python
    Replies:
    0
    Views:
    329
    Grant Edwards
    Sep 24, 2003
  2. news.easynet.be

    UrlLib2 Proxy and Https

    news.easynet.be, Dec 10, 2004, in forum: Python
    Replies:
    4
    Views:
    9,615
    Jacobo belbo
    Dec 13, 2004
  3. Fuzzyman

    urllib2, https, and proxies

    Fuzzyman, Jun 29, 2005, in forum: Python
    Replies:
    0
    Views:
    403
    Fuzzyman
    Jun 29, 2005
  4. Josef Cihal
    Replies:
    0
    Views:
    744
    Josef Cihal
    Sep 5, 2005
  5. Michele Simionato

    example of using urllib2 with https urls

    Michele Simionato, Oct 18, 2005, in forum: Python
    Replies:
    1
    Views:
    311
    Larry Bates
    Oct 18, 2005
Loading...

Share This Page