Skip to content

Instantly share code, notes, and snippets.

@thebookworm101
Created August 21, 2013 15:18
Show Gist options
  • Save thebookworm101/6295830 to your computer and use it in GitHub Desktop.
Save thebookworm101/6295830 to your computer and use it in GitHub Desktop.
## this is my simple tornado asynchttpclient that fetches files:
## trouble is its giving damaged pdf's on downdload, im using it
## with python 3.3.2, (with 2.7x i did not need to specify encoding
## but with python 3.3.2 i have to specify it, but still get corrupted
## file.
from tornado import ioloop, httpclient
def get_file(url):
http_client = httpclient.AsyncHTTPClient()
http_client.fetch(url, callback=done)
def done(response):
with open("filename.pdf", "w",encoding='utf-8') as f:
f.write(response.body.decode('latin-1'))
print ("DONE")
ioloop.IOLoop.instance().stop()
get_file("http://samplepdf.com/sample.pdf")
ioloop.IOLoop.instance().start()
## error on opening:
#Error: PDF file is damaged - attempting to reconstruct xref table...
#Error (323441): Bad FCHECK in flate stream
#Error (74): Bad FCHECK in flate stream
#Error (323441): Bad FCHECK in flate stream
#Error (74): Bad FCHECK in flate stream
#Error (323441): Bad FCHECK in flate stream
#Error (74): Bad FCHECK in flate stream
#Error (323441): Bad FCHECK in flate stream
#Error (74): Bad FCHECK in flate stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment