Skip to content

Commit 87afa59

Browse files
authored
Merge pull request #12 from bitmakerla/fix-proxy-rotation
Update proxy rotation
2 parents f2190d2 + 05439c0 commit 87afa59

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/ps_helper/middlewares/proxy_rotator.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff 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:

0 commit comments

Comments
 (0)