anusorn / httplib2

Automatically exported from code.google.com/p/httplib2
0 stars 0 forks source link

IndexError on jython #290

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
Run this simple code with jython

  import httplib2
  h = httplib2.Http()
  h.request("http://google.com")

What is the expected output? What do you see instead?

 - Expected: No output
 - Result: This exception:

  Traceback (most recent call last):
    File "test.py", line 3, in <module>
      h.request("http://google.com")
    File "/work/test/httplib2/__init__.py", line 1570, in request
      (response, content) = self._request(conn, authority, uri, request_uri, method, body, headers, redirections, cachekey)
    File "/work/test/httplib2/__init__.py", line 1317, in _request
      (response, content) = self._conn_request(conn, request_uri, method, body, headers)
    File "/work/test/httplib2/__init__.py", line 1252, in _conn_request
    conn.connect()
    File "/work/test/httplib2/__init__.py", line 1252, in _conn_request
      conn.connect()
    File "/work/test/httplib2/__init__.py", line 901, in connect
      self.sock.connect((self.host, self.port) + sa[2:])
    File "/work/test/httplib2/__init__.py", line 901, in connect
      self.sock.connect((self.host, self.port) + sa[2:])
    File "/usr/share/jython/Lib/socket.py", line 641, in __getitem__
      raise IndexError()
  IndexError

What version of the product are you using? On what operating system?

 - Httplib2: 0.8, 0.75, hg: 93291649202b
 - Jython: 2.5.2, 2.7b1

Original issue reported on code.google.com by manfr...@gmail.com on 10 Jul 2013 at 7:05

GoogleCodeExporter commented 9 years ago
This seems to be an issue where the socketaddr item returned by Jython's 
getaddrinfo is not a tuple, but an item that has limited similarities to a 
tuple. It does not support slicing, so running sa[2:] returns an IndexError 
instead of an empty tuple.

It's not obvious to me why httplib2 is doing

    (self.host, self.port) + sa[2:]

Which I believe should just be the same as 

    sa

This worked in Httpli2 0.7.2 before it split out using self.host and self.port 
from using the full sa tuple, but the heart of the problem is really Jython's 
implementation of the socketaddr item.

Jython has recently accepted a patch related to this issue, but I have no idea 
when there will be a final release of Jython that incorporates it.

Original comment by austin.r...@propylon.com on 30 Jun 2014 at 7:56