From 12c03f2359e50421824ae074dffda8e0fe93c028 Mon Sep 17 00:00:00 2001 From: "andrew.kuchling" Date: Fri, 27 Oct 2006 17:13:33 +0000 Subject: [PATCH] [Patch #1574068 by Scott Dial] urllib and urllib2 were using base64.encodestring() for encoding authentication data. encodestring() can include newlines for very long input, which produced broken HTTP headers. 2.4 backport candidate, probably. git-svn-id: http://svn.python.org/projects/python/branches/release25-maint@52482 6015fed2-1504-0410-9fe1-9d1591cc4771 --- Lib/urllib.py | 8 ++++---- Lib/urllib2.py | 4 ++-- Misc/NEWS | 3 +++ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Lib/urllib.py b/Lib/urllib.py index 8d5669075..064632c26 100644 --- a/Lib/urllib.py +++ b/Lib/urllib.py @@ -302,13 +302,13 @@ class URLopener: if proxy_passwd: import base64 - proxy_auth = base64.encodestring(proxy_passwd).strip() + proxy_auth = base64.b64encode(proxy_passwd).strip() else: proxy_auth = None if user_passwd: import base64 - auth = base64.encodestring(user_passwd).strip() + auth = base64.b64encode(user_passwd).strip() else: auth = None h = httplib.HTTP(host) @@ -387,12 +387,12 @@ class URLopener: if not host: raise IOError, ('https error', 'no host given') if proxy_passwd: import base64 - proxy_auth = base64.encodestring(proxy_passwd).strip() + proxy_auth = base64.b64encode(proxy_passwd).strip() else: proxy_auth = None if user_passwd: import base64 - auth = base64.encodestring(user_passwd).strip() + auth = base64.b64encode(user_passwd).strip() else: auth = None h = httplib.HTTPS(host, 0, diff --git a/Lib/urllib2.py b/Lib/urllib2.py index 3459f0d23..890d3d4a6 100644 --- a/Lib/urllib2.py +++ b/Lib/urllib2.py @@ -674,7 +674,7 @@ class ProxyHandler(BaseHandler): proxy_type = orig_type if user and password: user_pass = '%s:%s' % (unquote(user), unquote(password)) - creds = base64.encodestring(user_pass).strip() + creds = base64.b64encode(user_pass).strip() req.add_header('Proxy-authorization', 'Basic ' + creds) hostport = unquote(hostport) req.set_proxy(hostport, proxy_type) @@ -798,7 +798,7 @@ class AbstractBasicAuthHandler: user, pw = self.passwd.find_user_password(realm, host) if pw is not None: raw = "%s:%s" % (user, pw) - auth = 'Basic %s' % base64.encodestring(raw).strip() + auth = 'Basic %s' % base64.b64encode(raw).strip() if req.headers.get(self.auth_header, None) == auth: return None req.add_header(self.auth_header, auth) diff --git a/Misc/NEWS b/Misc/NEWS index 64fa7bf82..57e5ad0c3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -110,6 +110,9 @@ Library - Bug #1576241: fix functools.wraps() to work on built-in functions. +- Patch #1574068: fix urllib/urllib2 to not insert line breaks when + HTTP authentication data was very long. + - Fix a bug in traceback.format_exception_only() that led to an error being raised when print_exc() was called without an exception set. In version 2.4, this printed "None", restored that behavior. -- 2.11.4.GIT