bibibi12345 commited on
Commit
49b04cf
·
1 Parent(s): 2e0b729

proxy pool race condition fixed

Browse files
Files changed (1) hide show
  1. freeplay2api.py +18 -9
freeplay2api.py CHANGED
@@ -200,15 +200,24 @@ class FreeplayClient:
200
  continue
201
 
202
  logging.info(f"ABOUT TO MAKE REQUEST WITH PROXY {proxy_info['full'] if proxy_info else 'None'}")
203
- response = requests.post(
204
- url,
205
- data=json.dumps(payload),
206
- headers=headers,
207
- proxies=proxies,
208
- timeout=20,
209
- )
210
-
211
- logging.info(f"REQUEST COMPLETED WITH STATUS {response.status_code}")
 
 
 
 
 
 
 
 
 
212
 
213
  if response.status_code == 200:
214
  data = response.json()
 
200
  continue
201
 
202
  logging.info(f"ABOUT TO MAKE REQUEST WITH PROXY {proxy_info['full'] if proxy_info else 'None'}")
203
+ try:
204
+ response = requests.post(
205
+ url,
206
+ data=json.dumps(payload),
207
+ headers=headers,
208
+ proxies=proxies,
209
+ timeout=20,
210
+ )
211
+ logging.info(f"REQUEST COMPLETED WITH STATUS {response.status_code}")
212
+ except requests.exceptions.ProxyError as proxy_err:
213
+ logging.warning(f"CAUGHT PROXY ERROR: {proxy_err}")
214
+ if self.proxy_pool and proxy_info:
215
+ self.proxy_pool.remove_proxy(proxy_info['ip'], proxy_info['port'])
216
+ logging.info(f"CONTINUING AFTER INNER PROXY ERROR TO ATTEMPT {attempt + 1}")
217
+ continue
218
+ except Exception as inner_err:
219
+ logging.error(f"CAUGHT OTHER ERROR IN REQUEST: {inner_err}")
220
+ raise # Re-raise to be caught by outer handlers
221
 
222
  if response.status_code == 200:
223
  data = response.json()