urllib2 for HTTPS/SSL

Jeremy Hylton jeremy at alum.mit.edu
Tue Jul 8 08:54:44 EDT 2003


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







More information about the Python-list mailing list