Use the next() builtin for Python 3 compatibility

`iterator.next()` has been replaced by `next(iterator)` in Python 3.

Also add a test for retrying requests after a socket timeout.