[Python-talk] New Kent's Korner: urllib2 cookbook

Ric Werme ewerme at comcast.net
Tue Mar 25 08:15:36 EDT 2008

> Draft notes for the next Kent's Korner presentation are available at
> http://personalpages.tds.net/~kent37/kk/00010.html
> Comments welcome.

I've used urllib and urllib2, and I've wondered at times what needs to
be added to make it work with SSL (i.e. https:).  None of the examples
or other documentation I've looked at said anything about it, and between
urllib's debuglevel=1 outout and ethereal/wireshark data, I've never
had to look at the code much or go looking on the web for help.

It appears the answer is "It's already there, why didn't you try it before?"
I just tried it, and got the proper gobbledy-gook from ethereal and
this from python:

tux:climate> python
Python 2.4.2 (#1, Jun 21 2007, 14:06:12) 
[GCC 4.1.0 (SUSE Linux)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import urllib2
>>> f = urllib2.urlopen('https://www.dcu.org')
>>> p = f.read()
>>> print p[:500]
<!-- Primary Default Frameset File with coding to rotate 3 homepages on a 
3-day cycle-->
<!-- The homepages are home1.html, home2.html, and home3.html.-->
<!-- Updated by Tim Garner, DCU, 5/31/2006 -->

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<title>Digital Federal Credit Union</title>
<!--VISUAL SCIENCES CODE HBX2.0 (Universal)-->
No. 6,393,479B1. MORE INFO:http://visuals

ftp://user:pass@host:port works too

So, I suggest you add a brief section listing the protocols supported
by urllib2.  I see "The Missing Manual" does mention ftp early on but
only mentions suport for many protocols.  It's all too easy to associate
URL with HTTP, it was a long time before I realized it might do more than

  Coming soon - which way is the climate changing?
http://WermeNH.com/climate/science.html    ric at WermeNH.com

More information about the Python-talk mailing list