# Buggy code
def _download(url: str, save_path: str, filename: str):
    """Writes data from url to file."""
    if os.path.exists(os.path.join(save_path, filename)):
        logger.info("File %s already downloaded" % (os.path.join(save_path, filename)))
        return

    r = urllib.request.urlopen(url)
    logger.info("Downloading file at %s" % os.path.join(save_path, filename))

    def read_iter(file, block_size=1000):
        """Given a file 'file', returns an iterator that returns bytes of
        size 'blocksize' from the file, using read().
        """
        while True:
            block = file.read(block_size)
            if not block:
                break
            yield block

    # Create the path to save the data
    if not os.path.exists(save_path):
        os.makedirs(save_path)

    with open(os.path.join(save_path, filename), "wb") as f:
        for data in read_iter(r):
            f.write(data)


# Traceback (HTTPError)
---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-9-f56b0a5f9d5d> in <module>
2 get_ipython().run_line_magic('autoreload', '2')
3 from scvi.dataset import PbmcDataset
----> 4 d = PbmcDataset(save_path = 'test_asdffolder')

~/scVI/scvi/dataset/pbmc.py in __init__(self, save_path, save_path_10X, remove_extracted_data, delayed_populating)
54             filenames=["gene_info_pbmc.csv", "pbmc_metadata.pickle"],
55             save_path=save_path,
---> 56             delayed_populating=delayed_populating,
57         )
58         # this downloads the necessary file for a future call to populate

~/scVI/scvi/dataset/dataset.py in __init__(self, urls, filenames, save_path, delayed_populating)
2017         self.download()
2018         if not delayed_populating:
-> 2019             self.populate()
2020
2021     def download(self):

~/scVI/scvi/dataset/pbmc.py in populate(self)
83                 save_path=self.save_path_10X,
84                 remove_extracted_data=self.remove_extracted_data,
---> 85                 measurement_names_column=0,
86             ),
87             Dataset10X(

~/scVI/scvi/dataset/dataset10X.py in __init__(self, dataset_name, filename, save_path, url, type, dense, measurement_names_column, remove_extracted_data, delayed_populating)
154             filenames=filename,
155             save_path=save_path,
--> 156             delayed_populating=delayed_populating,
157         )
158

~/scVI/scvi/dataset/dataset.py in __init__(self, urls, filenames, save_path, delayed_populating)
2015
2016         self.save_path = os.path.abspath(save_path)
-> 2017         self.download()
2018         if not delayed_populating:
2019             self.populate()

~/scVI/scvi/dataset/dataset.py in download(self)
2021     def download(self):
2022         for url, download_name in zip(self.urls, self.filenames):
-> 2023             _download(url, self.save_path, download_name)
2024
2025     @abstractmethod

~/scVI/scvi/dataset/dataset.py in _download(url, save_path, filename)
2041     # req = urllib.request.Request(url, headers={"User-Agent": "Magic Browser"})
2042     # r = urllib.request.urlopen(req)
-> 2043     r = urllib.request.urlopen(url)
2044     logger.info("Downloading file at %s" % os.path.join(save_path, filename))
2045

~/anaconda3/envs/scvi/lib/python3.6/urllib/request.py in urlopen(url, data, timeout, cafile, capath, cadefault, context)
221     else:
222         opener = _opener
--> 223     return opener.open(url, data, timeout)
224
225 def install_opener(opener):

~/anaconda3/envs/scvi/lib/python3.6/urllib/request.py in open(self, fullurl, data, timeout)
530         for processor in self.process_response.get(protocol, []):
531             meth = getattr(processor, meth_name)
--> 532             response = meth(req, response)
533
534         return response

~/anaconda3/envs/scvi/lib/python3.6/urllib/request.py in http_response(self, request, response)
640         if not (200 <= code < 300):
641             response = self.parent.error(
--> 642                 'http', request, response, code, msg, hdrs)
643
644         return response

~/anaconda3/envs/scvi/lib/python3.6/urllib/request.py in error(self, proto, *args)
568         if http_err:
569             args = (dict, 'default', 'http_error_default') + orig_args
--> 570             return self._call_chain(*args)
571
572 # XXX probably also want an abstract factory that knows when it makes

~/anaconda3/envs/scvi/lib/python3.6/urllib/request.py in _call_chain(self, chain, kind, meth_name, *args)
502         for handler in handlers:
503             func = getattr(handler, meth_name)
--> 504             result = func(*args)
505             if result is not None:
506                 return result

~/anaconda3/envs/scvi/lib/python3.6/urllib/request.py in http_error_default(self, req, fp, code, msg, hdrs)
648 class HTTPDefaultErrorHandler(BaseHandler):
649     def http_error_default(self, req, fp, code, msg, hdrs):
--> 650         raise HTTPError(req.full_url, code, msg, hdrs, fp)
651
652 class HTTPRedirectHandler(BaseHandler):

HTTPError: HTTP Error 403: Forbidden```

#### Versions:
<!-- Output of scvi.__version__ -->
VERSION 0.6.6

# Fixed code
def _download(url: str, save_path: str, filename: str):
    """Writes data from url to file."""
    if os.path.exists(os.path.join(save_path, filename)):
        logger.info("File %s already downloaded" % (os.path.join(save_path, filename)))
        return
    try:
        r = urllib.request.urlopen(url)
    except HTTPError:
        req = urllib.request.Request(url, headers={"User-Agent": "Magic Browser"})
        r = urllib.request.urlopen(req)
    logger.info("Downloading file at %s" % os.path.join(save_path, filename))

    def read_iter(file, block_size=1000):
        """Given a file 'file', returns an iterator that returns bytes of
        size 'blocksize' from the file, using read().
        """
        while True:
            block = file.read(block_size)
            if not block:
                break
            yield block

    # Create the path to save the data
    if not os.path.exists(save_path):
        os.makedirs(save_path)

    with open(os.path.join(save_path, filename), "wb") as f:
        for data in read_iter(r):
            f.write(data)