473,386 Members | 1,705 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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.
Jul 18 '05 #1
5 26751
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/...-examples.html

Jeremy

Jul 18 '05 #2
> [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_
Jul 18 '05 #3
Jeremy Hylton <je****@alum.mit.edu> wrote in message news:<ma*********************************@python.o rg>...
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.
Jul 18 '05 #4
hw***@hotmail.com (Will Stuyvesant) wrote in message news:<cb**************************@posting.google. com>...
[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.
Jul 18 '05 #5
On Wed, 2003-07-09 at 05:29, Kylotan wrote:
Jeremy Hylton <je****@alum.mit.edu> wrote in message news:<ma*********************************@python.o rg>...
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

Jul 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: news.easynet.be | last post by:
Hello, I would like to access an HTTPS site via a proxy The following code is working for HTTP://www.hotmail.com but not for HTTPS I have try with other sites without success l_proxy_info = {...
1
by: Bloke | last post by:
I want to connect to a https server through an authenticating proxy like this: import urllib2 proxy_info = { 'user' : 'me', 'pass' : 'password', 'host' : 'mycompany.com.au', 'port' : 8008...
1
by: dmbkiwi | last post by:
I've been using urllib2 to try and automate logging into the google adsense page. I want to download the csv report files, so that I can do some analysis of them. However, I don't really know...
4
by: Bo Yang | last post by:
Hi , Recently I use python's urllib2 write a small script to login our university gateway . Usually , I must login into the gateway in order to surf the web . So , every time I start my computer...
3
by: jnair | last post by:
Hi , I am using python2.4 "urllib2" and "cookelib". In line "5" below i provide my credentials to login into a web site.During the first attempt i "fail", judging from the output of line "6"....
1
by: jnair | last post by:
Hi , I am using python2.4 "urllib2" and "cookelib". In line "5" below i provide my credentials to login into a web site.During the first attempt i "fail", judging from the output of line "6"....
3
by: itay_k | last post by:
Hi, I am running the following simple code (just open connection to some https page with proxy): proxy= '666.179.227.666:80' proxy=urllib2.ProxyHandler({"https":'https://'+proxy}) opener =...
0
by: Ali.Sabil | last post by:
hello all, I just maybe hit a bug in both urllib and urllib2, actually urllib doesn't support proxy authentication, and if you setup the http_proxy env var to...
1
by: Astan Chee | last post by:
Hi again, According to https://demo.launchpad.net/products/python/+bug/56872 or more specifically, the example of its working code:...
1
by: cp.finances.gouv | last post by:
Hello all, I'm facing a strange behavior of urllib2 trying to access gmail account behind a proxy (Squid). The following works perfectly : wget --save-cookies cookies...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.