[New-bugs-announce] [issue28539] httplib/http.client HTTPConnection._get_hostport() regression

Charles Stephens report at bugs.python.org
Wed Oct 26 15:12:47 EDT 2016


New submission from Charles Stephens:

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

----------
components: Library (Lib)
files: get_hostport.diff
keywords: patch
messages: 279509
nosy: cfs-pure
priority: normal
severity: normal
status: open
title: httplib/http.client HTTPConnection._get_hostport() regression
versions: Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6, Python 3.7
Added file: http://bugs.python.org/file45233/get_hostport.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28539>
_______________________________________


More information about the New-bugs-announce mailing list