@@ -105,7 +105,7 @@ def __init__(self, api_key, proxies=None):
105105 self .api_endpoint = render_api_endpoint
106106 self .proxies = proxies if proxies else {}
107107
108- def get_filing (self , url , as_pdf = False ):
108+ def get_filing (self , url , return_binary = False ):
109109 response = {}
110110 # remove "ix?doc=/" from URL
111111 filename = re .sub (r"ix\?doc=/" , "" , url )
@@ -116,7 +116,27 @@ def get_filing(self, url, as_pdf=False):
116116 for x in range (3 ):
117117 response = requests .get (_url , proxies = self .proxies )
118118 if response .status_code == 200 :
119- return response .text
119+ return response .text if not return_binary else response .content
120+ elif response .status_code == 429 :
121+ # wait 500 * (x + 1) milliseconds and try again
122+ time .sleep (0.5 * (x + 1 ))
123+ else :
124+ handle_api_error (response )
125+ else :
126+ handle_api_error (response )
127+
128+ def get_file (self , url , return_binary = False ):
129+ response = {}
130+ # remove "ix?doc=/" from URL
131+ filename = re .sub (r"ix\?doc=/" , "" , url )
132+ filename = re .sub (r"https://www.sec.gov/Archives/edgar/data" , "" , filename )
133+ _url = self .api_endpoint + filename + "?token=" + self .api_key
134+
135+ # use backoff strategy to handle "too many requests" error.
136+ for x in range (3 ):
137+ response = requests .get (_url , proxies = self .proxies )
138+ if response .status_code == 200 :
139+ return response .text if not return_binary else response .content
120140 elif response .status_code == 429 :
121141 # wait 500 * (x + 1) milliseconds and try again
122142 time .sleep (0.5 * (x + 1 ))
0 commit comments