feat(registration): Add email retry mechanism for API registration failures

- Add `allow_fallback` parameter to `register_openai_account_auto()` to control fallback behavior
- Return `"retry_new_email"` status when API registration fails without fallback enabled
- Return `"domain_blacklisted"` status when domain is blacklisted during registration
- Update `register_only()` to handle and propagate `"retry_new_email"` status
- Update `register_and_authorize()` to handle and propagate `"retry_new_email"` status
- Add retry logic in `process_accounts()` to regenerate email and reinvite on API failures
- Add retry logic in `_process_single_account_worker()` to regenerate email and reinvite on API failures
- Improve error handling to distinguish between domain blacklist and API failures requiring email regeneration
This commit is contained in:
2026-01-30 12:24:40 +08:00
parent e4f330500d
commit 79c3eb733c
2 changed files with 75 additions and 9 deletions

40
run.py
View File

@@ -453,6 +453,29 @@ def process_accounts(accounts: list, team_name: str, team_index: int = 0,
log.error("无法创建有效的新邮箱")
continue # 跳过当前账号,继续下一个
# 检查是否需要重新生成邮箱重试 (API 模式失败)
if register_success == "retry_new_email":
log.warning("API 注册失败,重新生成邮箱重试...")
# 从 tracker 中移除旧邮箱
remove_account_from_tracker(_tracker, team_name, email)
save_team_tracker(_tracker)
# 创建新邮箱
new_email, new_password = unified_create_email()
if new_email and not is_email_blacklisted(new_email):
# 邀请新邮箱
if invite_single_to_team(new_email, _get_team_by_name(team_name)):
add_account_with_password(_tracker, team_name, new_email, new_password, "invited")
save_team_tracker(_tracker)
log.success(f"已创建新邮箱: {new_email},将在下次运行时处理")
else:
log.error("新邮箱邀请失败")
else:
log.error("无法创建有效的新邮箱")
continue # 跳过当前账号,继续下一个
if register_success and register_success != "domain_blacklisted":
update_account_status(_tracker, team_name, email, "registered")
@@ -691,6 +714,23 @@ def _process_single_account_worker(
remove_account_from_tracker(_tracker, team_name, email)
save_team_tracker(_tracker)
return result
# 检查是否需要重新生成邮箱重试 (API 模式失败)
if register_success == "retry_new_email":
log.warning(f"[Worker-{worker_id}] API 注册失败,重新生成邮箱重试...")
with _tracker_lock:
remove_account_from_tracker(_tracker, team_name, email)
save_team_tracker(_tracker)
# 创建新邮箱并邀请
new_email, new_password = unified_create_email()
if new_email and not is_email_blacklisted(new_email):
if invite_single_to_team(new_email, _get_team_by_name(team_name)):
with _tracker_lock:
add_account_with_password(_tracker, team_name, new_email, new_password, "invited")
save_team_tracker(_tracker)
log.success(f"[Worker-{worker_id}] 已创建新邮箱: {new_email}")
return result
if register_success and register_success != "domain_blacklisted":
with _tracker_lock: