Fixed fetching files on newer versions of Python

This commit is contained in:
Sworddragon 2014-06-19 19:58:50 +02:00
parent e1739f59be
commit 2f454b21fd

View file

@ -7,10 +7,17 @@ elif sys.version_info[0] == 3:
url_lib = urllib.request url_lib = urllib.request
def fetch_file(url): def fetch_file(url):
try:
print("trying %s" % url) print("trying %s" % url)
local = dict(url_lib.urlopen(url).info())["content-disposition"].split("=")[1] try:
local = dict(url_lib.urlopen(url).info())
if "Content-Disposition" in local:
key_name = "Content-Disposition"
elif "content-disposition" in local:
key_name = "content-disposition"
else:
return False
local = local[key_name].split("=")[1]
url_lib.urlretrieve(url, local) url_lib.urlretrieve(url, local)
return local return local
except: except IOError:
return False return False