This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Bugfix for urllib2.py
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jhylton Nosy List: gvanrossum, jemfinch, jhylton, nobody
Priority: normal Keywords: patch

Created on 2002-08-25 07:25 by jemfinch, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patch jemfinch, 2002-08-25 07:25 Patch for urllib2.py
patch jemfinch, 2002-08-25 19:45 New Patch (oops, forgot to change *args to name, value :))
Messages (7)
msg41021 - (view) Author: Jeremy Fincher (jemfinch) Date: 2002-08-25 07:25
OpenerDirector has a default User-agent header.  That 
wouldn't be a problem, except that 
AbstractHTTPHandler uses the headers in 
OpenerDirector.addheaders *after* a Request has been 
instantiated, thus making that default override whatever 
headers were given to Request.  This patch checks to 
make sure a header isn't already in a Request before 
adding the OpenerDirector's headers.
msg41022 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-09-03 18:56
Logged In: YES 
user_id=6380

For Jeremy.
msg41023 - (view) Author: Nobody/Anonymous (nobody) Date: 2002-09-06 15:50
Logged In: NO 

Unless you want problems, I suggest you to use the same case
as Mozilla, IE and the RFC in the User-Agent HTTP header.

--- python/dist/src/Lib/urllib.py
+++ python/dist/src/Lib/urllib.py
@@ -104,7 +104,7 @@
         self.proxies = proxies
         self.key_file = x509.get('key_file')
         self.cert_file = x509.get('cert_file')
-        self.addheaders = [('User-agent', self.version)]
+        self.addheaders = [('User-Agent', self.version)]
         self.__tempfiles = []
         self.__unlink = os.unlink # See cleanup()
         self.tempcache = None
--- python/dist/src/Lib/urllib2.py
+++ python/dist/src/Lib/urllib2.py
@@ -247,7 +247,7 @@
 class OpenerDirector:
     def __init__(self):
         server_version = "Python-urllib/%s" % __version__
-        self.addheaders = [('User-agent', server_version)]
+        self.addheaders = [('User-Agent', server_version)]
         # manage the individual handlers
         self.handlers = []
         self.handle_open = {}
msg41024 - (view) Author: Nobody/Anonymous (nobody) Date: 2002-09-10 18:17
Logged In: NO 

Is there any reasons to not use the same case as Mozilla, IE
and the RFC in the User-Agent HTTP header?
msg41025 - (view) Author: Jeremy Hylton (jhylton) (Python triager) Date: 2002-10-11 17:27
Logged In: YES 
user_id=31392

Fixed in rev 1.36.

Changed case, even though the headers aren't case sensitive.
msg41026 - (view) Author: Nobody/Anonymous (nobody) Date: 2002-10-13 14:32
Logged In: NO 

Please also patch "urllib2.py" not only "urllib.py"
--- python/dist/src/Lib/urllib.py
+++ python/dist/src/Lib/urllib.py
@@ -104,7 +104,7 @@
         self.proxies = proxies
         self.key_file = x509.get('key_file')
         self.cert_file = x509.get('cert_file')
-        self.addheaders = [('User-agent', self.version)]
+        self.addheaders = [('User-Agent', self.version)]
         self.__tempfiles = []
         self.__unlink = os.unlink # See cleanup()
         self.tempcache = None
msg41027 - (view) Author: Nobody/Anonymous (nobody) Date: 2002-10-15 15:26
Logged In: NO 

Could you also patch "urllib.py"?
If you don't want to, please add an explanation here.
History
Date User Action Args
2022-04-10 16:05:37adminsetgithub: 37085
2002-08-25 07:25:22jemfinchcreate