File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 22import ssl
33import urllib .request
44from typing import List
5+ from urllib .error import HTTPError
56
67from pypdf .generic import DictionaryObject , IndirectObject
78
@@ -30,10 +31,19 @@ def get_pdf_from_url(url: str, name: str) -> bytes:
3031 cache_path = os .path .join (cache_dir , name )
3132 if not os .path .exists (cache_path ):
3233 ssl ._create_default_https_context = ssl ._create_unverified_context
33- with urllib .request .urlopen (url ) as response , open (
34- cache_path , "wb"
35- ) as out_file :
36- out_file .write (response .read ())
34+ cpt = 3
35+ while cpt > 0 :
36+ try :
37+ with urllib .request .urlopen (url ) as response , open (
38+ cache_path , "wb"
39+ ) as out_file :
40+ out_file .write (response .read ())
41+ cpt = 0
42+ except HTTPError as e :
43+ if cpt > 0 :
44+ cpt -= 1
45+ else :
46+ raise e
3747 with open (cache_path , "rb" ) as fp :
3848 data = fp .read ()
3949 return data
You can’t perform that action at this time.
0 commit comments