File tree Expand file tree Collapse file tree
src/ps_helper/middlewares Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -201,11 +201,31 @@ def get_next_proxy(self):
201201 return random .choice (available )
202202
203203 def _ban_proxy (self , proxy ):
204+ if proxy not in self .proxy_stats :
205+ self .proxy_stats [proxy ] = {
206+ "requests" : 0 ,
207+ "success" : 0 ,
208+ "fails" : 0 ,
209+ "banned_until" : 0 ,
210+ }
204211 stats = self .proxy_stats [proxy ]
205212 stats ["banned_until" ] = time .time () + self .cooldown_time
206213 logger .info (f"[Smart] Proxy temporarily banned: { proxy } " )
207214
208215 def register_failure (self , proxy ):
216+ if proxy not in self .proxy_stats :
217+ for full_proxy in self .proxy_stats .keys ():
218+ if proxy in full_proxy or full_proxy .endswith (proxy .replace ("http://" , "" )):
219+ proxy = full_proxy
220+ break
221+ else :
222+ self .proxy_stats [proxy ] = {
223+ "requests" : 0 ,
224+ "success" : 0 ,
225+ "fails" : 0 ,
226+ "banned_until" : 0 ,
227+ }
228+
209229 stats = self .proxy_stats [proxy ]
210230 stats ["fails" ] += 1
211231 if stats ["fails" ] >= self .ban_threshold :
You can’t perform that action at this time.
0 commit comments