python urllib corrupts downloaded documents

201 Views Asked by At

For some reason urllib is corrupting documents that i download from a website. The url is definitely correct. The documents download with their correct names but they appear corrupted once opened. There is no encoding on the files so i don't need to decode it. I would really appreciate some help in this problem. Here is a snippet:

def download_file(url, name):

f = urllib.urlopen(url)
fh = open(name, 'wb')
fh.write(f.read())
fh.close()
print "  File Downloaded : " , name

except Exception:
    raise
0

There are 0 best solutions below