urllib2 for HTTPS/SSL

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kylotan

    urllib2 for HTTPS/SSL

    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.
  • Jeremy Hylton

    #2
    Re: urllib2 for HTTPS/SSL

    On Tue, 2003-07-08 at 06:33, Kylotan wrote:[color=blue]
    > 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?[/color]

    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:



    Jeremy



    Comment

    • Will Stuyvesant

      #3
      Re: urllib2 for HTTPS/SSL

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

      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_

      Comment

      • Kylotan

        #4
        Re: urllib2 for HTTPS/SSL

        Jeremy Hylton <[email protected] t.edu> wrote in message news:<mailman.1 057668851.8514. [email protected] >...[color=blue]
        > On Tue, 2003-07-08 at 06:33, Kylotan wrote:[color=green]
        > > 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?[/color]
        >
        > 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.)[/color]

        Ok, so what you're saying is that the stuff documented in:
        "Python Library Reference - 11.5.14 HTTPSHandler Objects"
        is purely an implementationa l 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.

        Comment

        • Kylotan

          #5
          Re: urllib2 for HTTPS/SSL

          [email protected] om (Will Stuyvesant) wrote in message news:<cb035744. 0307081242.44bc [email protected] ogle.com>...[color=blue][color=green]
          > > [Kylotan]
          > > ............... .........Is there any chance of the official
          > > documentation on this useful-looking module being improved?[/color]
          >
          > 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.[/color]

          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.

          Comment

          • Jeremy Hylton

            #6
            Re: urllib2 for HTTPS/SSL

            On Wed, 2003-07-09 at 05:29, Kylotan wrote:[color=blue]
            > Jeremy Hylton <[email protected] t.edu> wrote in message news:<mailman.1 057668851.8514. [email protected] >...[color=green]
            > > On Tue, 2003-07-08 at 06:33, Kylotan wrote:[color=darkred]
            > > > 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?[/color]
            > >
            > > 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.)[/color]
            >
            > Ok, so what you're saying is that the stuff documented in:
            > "Python Library Reference - 11.5.14 HTTPSHandler Objects"
            > is purely an implementationa l 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?[/color]

            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.
            [color=blue]
            > I'm guessing the OpenerDirector object tries the URL with each
            > BaseHandler-derived object to see which one should handle it.[/color]

            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



            Comment

            Working...