title: Python async/await downloading a list of urls
body: <p>I'm trying to download over 30,000 files from a FTP server, and after some googling using asynchronous IO seemed a good idea. However, the code below failed to download any files and returns a Timeout Error. I'd really appreciate any help! Thanks!</p>
  
  <pre><code>class pdb:
      def __init__(self):
          self.ids = []
          self.dl_id = []
          self.err_id = []
  
  
      async def download_file(self, session, url):
          try:
              with async_timeout.timeout(10):
                  async with session.get(url) as remotefile:
                      if remotefile.status == 200:
                          data = await remotefile.read()
                          return {"error": "", "data": data}
                      else:
                          return {"error": remotefile.status, "data": ""}
          except Exception as e:
              return {"error": e, "data": ""}
  
      async def unzip(self, session, work_queue):
          while not work_queue.empty():
              queue_url = await work_queue.get()
              print(queue_url)
              data = await self.download_file(session, queue_url)
              id = queue_url[-11:-7]
              ID = id.upper()
              if not data["error"]:
                  saved_pdb = os.path.join("./pdb", ID, f'{ID}.pdb')
                  if ID not in self.dl_id:
                      self.dl_id.append(ID)
                  with open(f"{id}.ent.gz", 'wb') as f:
                      f.write(data["data"].read())
                  with gzip.open(f"{id}.ent.gz", "rb") as inFile, open(saved_pdb, "wb") as outFile:
                      shutil.copyfileobj(inFile, outFile)
                  os.remove(f"{id}.ent.gz")
              else:
                  self.err_id.append(ID)
  
      def download_queue(self, urls):
          loop = asyncio.get_event_loop()
          q = asyncio.Queue(loop=loop)
          [q.put_nowait(url) for url in urls]
          con = aiohttp.TCPConnector(limit=10)
          with aiohttp.ClientSession(loop=loop, connector=con) as session:
              tasks = [asyncio.ensure_future(self.unzip(session, q)) for _ in range(len(urls))]
              loop.run_until_complete(asyncio.gather(*tasks))
          loop.close()
  </code></pre>
  
  <p>Error message if I remove the <code>try</code> part:  </p>
  
  <blockquote>
    <p>Traceback (most recent call last):<br>
    File "test.py", line 111, in <br>
        x.download_queue(urls)<br>
    File "test.py", line 99, in download_queue<br>
        loop.run_until_complete(asyncio.gather(*tasks))<br>
    File "/home/yz/miniconda3/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete<br>
        return future.result()<br>
    File "test.py", line 73, in unzip<br>
        data = await self.download_file(session, queue_url)<br>
    File "test.py", line 65, in download_file<br>
        return {"error": remotefile.status, "data": ""}<br>
    File "/home/yz/miniconda3/lib/python3.6/site- packages/async_timeout/<strong>init</strong>.py", line 46, in <strong>exit</strong><br>
        raise asyncio.TimeoutError from None<br>
    concurrent.futures._base.TimeoutError  </p>
  </blockquote>