Merge pull request #831 from Gluejar/more_online

add exception handling in stapler
pull/94/head
eshellman 2019-03-04 19:48:16 -05:00 committed by GitHub
commit e618e5da8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 1 deletions

View File

@ -66,7 +66,11 @@ def test_pdf(pdf_file):
def staple_pdf(urllist, user_agent=settings.USER_AGENT): def staple_pdf(urllist, user_agent=settings.USER_AGENT):
merger = PdfFileMerger(strict=False) merger = PdfFileMerger(strict=False)
for url in urllist: for url in urllist:
try:
response = requests.get(url, headers={"User-Agent": user_agent}) response = requests.get(url, headers={"User-Agent": user_agent})
except requests.exceptions.ConnectionError:
logger.error("Error getting url: %s", url)
return None
if response.status_code == 200: if response.status_code == 200:
try: try:
merger.append(BytesIO(response.content)) merger.append(BytesIO(response.content))