bibibi12345 commited on
Commit
dd25943
·
1 Parent(s): 9ed488f

proxy pool race condition fixed

Browse files
Files changed (1) hide show
  1. freeplay2api.py +11 -1
freeplay2api.py CHANGED
@@ -158,6 +158,7 @@ class FreeplayClient:
158
  return 0.0
159
 
160
  def register(self) -> Optional[Dict]:
 
161
  url = "https://app.freeplay.ai/app_data/auth/signup"
162
  headers = {
163
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36",
@@ -168,8 +169,10 @@ class FreeplayClient:
168
  }
169
 
170
  attempt = 0
 
171
  while attempt < 50: # Try up to 50 times
172
  attempt += 1
 
173
  proxy_info = None
174
  try:
175
  # Wait for proxy pool to be ready
@@ -198,6 +201,8 @@ class FreeplayClient:
198
  timeout=20,
199
  )
200
 
 
 
201
  if response.status_code == 200:
202
  data = response.json()
203
  project_id = data.get("project_id")
@@ -213,21 +218,26 @@ class FreeplayClient:
213
  }
214
 
215
  logging.warning(f"Registration attempt {attempt}/50 failed with status {response.status_code}: {response.text}")
 
216
 
217
  except requests.exceptions.ProxyError as e:
218
  logging.warning(f"Proxy error during registration on attempt {attempt}/50: {e}. Retrying with a new proxy...")
219
  if self.proxy_pool and proxy_info:
220
  self.proxy_pool.remove_proxy(proxy_info['ip'], proxy_info['port'])
 
221
 
222
  except requests.exceptions.RequestException as e:
223
  logging.warning(f"Request exception during registration on attempt {attempt}/50: {e}. Retrying...")
224
  if self.proxy_pool and proxy_info:
225
  self.proxy_pool.remove_proxy(proxy_info['ip'], proxy_info['port'])
 
226
 
227
  except Exception as e:
228
  logging.error(f"An unexpected error occurred during registration on attempt {attempt}/50: {e}. Retrying...")
 
229
 
230
  logging.error("Failed to register a new account after 50 attempts.")
 
231
  return None
232
  def chat(
233
  self,
@@ -406,7 +416,7 @@ def initialize_app():
406
  "ACCOUNTS_FILE": "accounts.json",
407
  "LOW_BALANCE_THRESHOLD": 2.0,
408
  "ACTIVE_KEY_THRESHOLD": 5,
409
- "CHECK_INTERVAL_SECONDS": 300,
410
  "REGISTRATION_CONCURRENCY": 2,
411
  "USE_PROXY_POOL": True,
412
  "PROXY_POOL_CONFIG": {
 
158
  return 0.0
159
 
160
  def register(self) -> Optional[Dict]:
161
+ logging.info("REGISTER FUNCTION STARTED")
162
  url = "https://app.freeplay.ai/app_data/auth/signup"
163
  headers = {
164
  "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36",
 
169
  }
170
 
171
  attempt = 0
172
+ logging.info("STARTING RETRY LOOP")
173
  while attempt < 50: # Try up to 50 times
174
  attempt += 1
175
+ logging.info(f"LOOP ITERATION {attempt} STARTED")
176
  proxy_info = None
177
  try:
178
  # Wait for proxy pool to be ready
 
201
  timeout=20,
202
  )
203
 
204
+ logging.info(f"REQUEST COMPLETED WITH STATUS {response.status_code}")
205
+
206
  if response.status_code == 200:
207
  data = response.json()
208
  project_id = data.get("project_id")
 
218
  }
219
 
220
  logging.warning(f"Registration attempt {attempt}/50 failed with status {response.status_code}: {response.text}")
221
+ logging.info(f"CONTINUING TO NEXT ATTEMPT {attempt + 1}")
222
 
223
  except requests.exceptions.ProxyError as e:
224
  logging.warning(f"Proxy error during registration on attempt {attempt}/50: {e}. Retrying with a new proxy...")
225
  if self.proxy_pool and proxy_info:
226
  self.proxy_pool.remove_proxy(proxy_info['ip'], proxy_info['port'])
227
+ logging.info(f"CONTINUING AFTER PROXY ERROR TO ATTEMPT {attempt + 1}")
228
 
229
  except requests.exceptions.RequestException as e:
230
  logging.warning(f"Request exception during registration on attempt {attempt}/50: {e}. Retrying...")
231
  if self.proxy_pool and proxy_info:
232
  self.proxy_pool.remove_proxy(proxy_info['ip'], proxy_info['port'])
233
+ logging.info(f"CONTINUING AFTER REQUEST EXCEPTION TO ATTEMPT {attempt + 1}")
234
 
235
  except Exception as e:
236
  logging.error(f"An unexpected error occurred during registration on attempt {attempt}/50: {e}. Retrying...")
237
+ logging.info(f"CONTINUING AFTER UNEXPECTED ERROR TO ATTEMPT {attempt + 1}")
238
 
239
  logging.error("Failed to register a new account after 50 attempts.")
240
+ logging.info("REGISTER FUNCTION ENDING")
241
  return None
242
  def chat(
243
  self,
 
416
  "ACCOUNTS_FILE": "accounts.json",
417
  "LOW_BALANCE_THRESHOLD": 2.0,
418
  "ACTIVE_KEY_THRESHOLD": 5,
419
+ "CHECK_INTERVAL_SECONDS": 5,
420
  "REGISTRATION_CONCURRENCY": 2,
421
  "USE_PROXY_POOL": True,
422
  "PROXY_POOL_CONFIG": {