# Buggy code
def download(self, url, file_path=None, auth=None):
    ret = bytearray()
    response = self.requester.get(url, stream=True, verify=self.verify, auth=auth)
    if not response.ok:
        raise ConanException(
            "Error %d downloading file %s" % (response.status_code, url)
        )

    try:
        total_length = response.headers.get("content-length")

        if total_length is None:  # no content length header
            if not file_path:
                ret += response.content
            else:
                save(file_path, response.content, append=True)
        else:
            dl = 0
            total_length = int(total_length)
            last_progress = None
            chunk_size = 1024 if not file_path else 1024 * 100
            for data in response.iter_content(chunk_size=chunk_size):
                dl += len(data)
                if not file_path:
                    ret.extend(data)
                else:
                    save(file_path, data, append=True)

                units = progress_units(dl, total_length)
                if last_progress != units:  # Avoid screen refresh if nothing has change
                    if self.output:
                        print_progress(self.output, units)
                    last_progress = units

        return bytes(ret)
    except Exception as e:
        logger.debug(e.__class__)
        logger.debug(traceback.format_exc())
        # If this part failed, it means problems with the connection to server
        raise ConanConnectionError(
            "Download failed, check server, possibly try again\n%s" % str(e)
        )


# Traceback (exceptions.MemoryError)
DEBUG :uploader_downloader.py[74]: <type 'exceptions.MemoryError'> [2016-09-23 15:15:02,983]
DEBUG :uploader_downloader.py[75]: Traceback (most recent call last):
File "c:\python27\lib\site-packages\conans\client\rest\uploader_downloader.py", line 62, in download
ret.extend(data)
MemoryError

# Fixed code
def download(self, url, file_path=None, auth=None):
    ret = bytearray()
    response = self.requester.get(url, stream=True, verify=self.verify, auth=auth)
    if not response.ok:
        raise ConanException(
            "Error %d downloading file %s" % (response.status_code, url)
        )

    try:
        total_length = response.headers.get("content-length")

        if total_length is None:  # no content length header
            if not file_path:
                ret += response.content
            else:
                save(file_path, response.content, append=True)
        else:
            dl = 0
            total_length = int(total_length)
            last_progress = None
            chunk_size = 1024 if not file_path else 1024 * 100
            for data in response.iter_content(chunk_size=chunk_size):
                dl += len(data)
                if not file_path:
                    ret.extend(data)
                else:
                    save(file_path, data, append=True)

                units = progress_units(dl, total_length)
                if last_progress != units:  # Avoid screen refresh if nothing has change
                    if self.output:
                        print_progress(self.output, units)
                    last_progress = units
        if not file_path:
            return bytes(ret)
        else:
            return
    except Exception as e:
        logger.debug(e.__class__)
        logger.debug(traceback.format_exc())
        # If this part failed, it means problems with the connection to server
        raise ConanConnectionError(
            "Download failed, check server, possibly try again\n%s" % str(e)
        )