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.

Author cfs-pure
Recipients cfs-pure
Date 2016-10-26.19:12:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1477509167.25.0.917011281654.issue28539@psf.upfronthosting.co.za>
In-reply-to
Content
Back through the mists of time, there was a change to strip square brackets IPv6 address host literals in HTTPConnection._get_hostport():

https://hg.python.org/cpython/diff/433606e9546c/Lib/httplib.py

However, the code mixed tabs and spaces and was "corected" by:

https://hg.python.org/cpython/diff/9e2b94a3b5dc/Lib/httplib.py

However, the intent was changed in the second diff and brackets won't be stripped.  This causes problems when IPv6 address URL's are used with the requests package:

In [1]: import httplib

In [2]: con = httplib.HTTPConnection('[fe80::26a9:37ff:fe00:f764%eth0]', 15482)

In [3]: con.request("GET", "/api/api-version")
---------------------------------------------------------------------------
gaierror                                  Traceback (most recent call last)
<ipython-input-3-28f1bab26dc1> in <module>()
----> 1 con.request("GET", "/api/api-version")

/usr/lib/python2.7/httplib.pyc in request(self, method, url, body, headers)
    977     def request(self, method, url, body=None, headers={}):
    978         """Send a complete request to the server."""
--> 979         self._send_request(method, url, body, headers)
    980 
    981     def _set_content_length(self, body):

/usr/lib/python2.7/httplib.pyc in _send_request(self, method, url, body, headers)
   1011         for hdr, value in headers.iteritems():
   1012             self.putheader(hdr, value)
-> 1013         self.endheaders(body)
   1014 
   1015     def getresponse(self, buffering=False):

/usr/lib/python2.7/httplib.pyc in endheaders(self, message_body)
    973         else:
    974             raise CannotSendHeader()
--> 975         self._send_output(message_body)
    976 
    977     def request(self, method, url, body=None, headers={}):

/usr/lib/python2.7/httplib.pyc in _send_output(self, message_body)
    833             msg += message_body
    834             message_body = None
--> 835         self.send(msg)
    836         if message_body is not None:
    837             #message_body was not a string (i.e. it is a file) and

/usr/lib/python2.7/httplib.pyc in send(self, data)
    795         if self.sock is None:
    796             if self.auto_open:
--> 797                 self.connect()
    798             else:
    799                 raise NotConnected()

/usr/lib/python2.7/httplib.pyc in connect(self)
    776         """Connect to the host and port specified in __init__."""
    777         self.sock = socket.create_connection((self.host,self.port),
--> 778                                              self.timeout, self.source_address)
    779 
    780         if self._tunnel_host:

/usr/lib/python2.7/socket.pyc in create_connection(address, timeout, source_address)
    551     host, port = address
    552     err = None
--> 553     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
    554         af, socktype, proto, canonname, sa = res
    555         sock = None

gaierror: [Errno -2] Name or service not known
History
Date User Action Args
2016-10-26 19:12:47cfs-puresetrecipients: + cfs-pure
2016-10-26 19:12:47cfs-puresetmessageid: <1477509167.25.0.917011281654.issue28539@psf.upfronthosting.co.za>
2016-10-26 19:12:47cfs-purelinkissue28539 messages
2016-10-26 19:12:45cfs-purecreate