[Tutor] urllib confusion

Alan Gauld alan.gauld at btinternet.com
Sat Nov 22 00:48:05 CET 2014

On 21/11/14 21:37, Clayton Kirkwood wrote:

> urllib or urllib2 modules are being deprecated in 3.5. Don’t know if
> it’s only part or whole.

urlib2 doesn't exist in Python3 there is only the urllib package.

As to urllib being deprecated, thats the first I've heard of
it but it may be the case - I don;t follow the new releases closely 
since I'm usually at least 2 releases behind. I only upgraded to 3.4 
because I was writing the new book and needed it to be as current as 

But the "What's New" document for the 3.5 alpha says:

"A new urllib.request.HTTPBasicPriorAuthHandler allows HTTP Basic 
Authentication credentials to be sent unconditionally with the first 
HTTP request, rather than waiting for a HTTP 401 Unauthorized response 
from the server. (Contributed by Matej Cepl in issue 19494.)"

And the NEWS file adds:

"urllib.request.urlopen will accept a context object
  (SSLContext) as an argument which will then used be
for HTTPS connection.  Patch by Alex Gaynor."

Which suggests urllib is alive and kicking...

> I’ve read through a lot that says that urllib..urlopen needs urlencode,
> and/or encode(‘utf-8’) for byte conversion, but I’ve seen plenty of
> examples where nothing is being encoded either way.

Might those be v2 examples?
encoding got a whole lot more specific in Python v3.

But I'm not sure what you mean by the double dot.
urllib.urlopen is discontinued in Python3. You
should be using urllib.request.urlopen instead.
(But maybe thats what you meant by the ..?)

> Why do so many examples seem to not encode? And not get TypeError?

Without specific examples it's hard to know.

Alan G
Author of the Learn to Program web site
Follow my phopto-blog on Flickr at:

More information about the Tutor mailing list