Python 2 compatibility

socket.error is a (deprecated) alias for OSError since Python 3, but in
Python 2, OSError does not include socket errors.