Guest User

Untitled

a guest
Aug 12th, 2015
493
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. from urllib.request import urlretrieve
  2. import requests
  3. from multiprocessing import Pool
  4.  
  5. def download(i):
  6.     try:
  7.         headers = requests.head("http://www.site.com/scripts/getfile.php?id={}".format(i))
  8.     except:
  9.         print("Unable to reach file " + str(i))
  10.         return None
  11.     try:
  12.         filename = headers.headers["content-disposition"].replace("filename=", "")
  13.         filename = "{}_{}".format(i, filename)
  14.     except:
  15.         filename = str(i)
  16.     urlretrieve("http://www.site.com/scripts/getfile.php?id={}".format(i), "/Volumes/SeagateExpansion/Database/{}".format(filename))
  17.     print("Downloaded {}".format(filename))
  18.  
  19. p = Pool(processes = 16)
  20. p.map(download, range(70000))
  21. p.close()
  22. p.join()
  23.  
  24.  
  25. ERROR:
  26. Traceback (most recent call last):
  27.   File "/Users/MyUsername/Dropbox/Python/Projects/FileDownloader.py", line 20, in <module>
  28.     p.map(download, range(70000))
  29.   File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/multiprocessing/pool.py", line 260, in map
  30.     return self._map_async(func, iterable, mapstar, chunksize).get()
  31.   File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/multiprocessing/pool.py", line 599, in get
  32.     raise self._value
  33. multiprocessing.pool.MaybeEncodingError: Error sending result: '<multiprocessing.pool.ExceptionWithTraceback object at 0x1027a67f0>'. Reason: 'TypeError("cannot serialize '_io.BufferedReader' object",)'
Advertisement
Add Comment
Please, Sign In to add comment