Python Requests get doesn't return unless a timeout is specified -
this request never returns (or @ least not within patience):
import requests r = requests.get('http://en.wikipedia.org/w/api.php?rcprop=ids&format=json&action=query&rclimit=10&rctype=edit&list=recentchanges&rcnamespace=0', headers={'user-agent': 'api test'})
hitting ctrl+c produces traceback:
^ctraceback (most recent call last): file "<stdin>", line 1, in <module> file "/usr/lib/python2.7/dist-packages/requests/api.py", line 55, in return request('get', url, **kwargs) file "/usr/lib/python2.7/dist-packages/requests/api.py", line 44, in request return session.request(method=method, url=url, **kwargs) file "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 383, in request resp = self.send(prep, **send_kwargs) file "/usr/lib/python2.7/dist-packages/requests/sessions.py", line 486, in send r = adapter.send(request, **kwargs) file "/usr/lib/python2.7/dist-packages/requests/adapters.py", line 330, in send timeout=timeout file "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 542, in urlopen body=body, headers=headers) file "/usr/lib/python2.7/dist-packages/urllib3/connectionpool.py", line 367, in _make_request conn.request(method, url, **httplib_request_kw) file "/usr/lib/python2.7/httplib.py", line 973, in request self._send_request(method, url, body, headers) file "/usr/lib/python2.7/httplib.py", line 1007, in _send_request self.endheaders(body) file "/usr/lib/python2.7/httplib.py", line 969, in endheaders self._send_output(message_body) file "/usr/lib/python2.7/httplib.py", line 829, in _send_output self.send(msg) file "/usr/lib/python2.7/httplib.py", line 791, in send self.connect() file "/usr/lib/python2.7/httplib.py", line 772, in connect self.timeout, self.source_address) file "/usr/lib/python2.7/socket.py", line 562, in create_connection sock.connect(sa) file "/usr/lib/python2.7/socket.py", line 224, in meth return getattr(self._sock,name)(*args)
adding timeout=5
request causes request succeed, after timeout has expired (ie correct data returned api request). of course adds 5 seconds of latency application every api request.
what's going wrong here?
this due ipv6 not working on network. httplib (and therefore requests) seems prefer ipv6 if it's available, if it's not working can have long wait while ipv6 request times out. setting timeout causes fall ipv4 following expiry of timeout, succeeds. disabling ipv6 on network has fixed (as, assume, fixing ipv6).