修复多个bug并增强调试功能
修复的bug: 1. email_service.py: 验证码提取失败 - 从邮件Subject提取验证码(格式: XXX-XXX xAI confirmation code) 2. nsfw_service.py: enable_unhinged cookie错误 - sso-rw被错误设置为sso的值 3. grok.py: URL路径错误 - 分离base_url和site_url,修复重复/sign-up 4. api_solver.py: Turnstile JS语法错误 - return语句在全局作用域非法,包装为IIFE 增强功能: - 添加详细调试日志,便于定位问题 - 改进Turnstile solver等待逻辑,检测API可用性 - 添加更多错误处理和状态输出
This commit is contained in:
@@ -32,24 +32,56 @@ class EmailService:
|
||||
print(f"[-] 创建邮箱失败: {e}")
|
||||
return None, None
|
||||
|
||||
def fetch_verification_code(self, email, max_attempts=30):
|
||||
def fetch_verification_code(self, email, max_attempts=30, debug=False):
|
||||
"""轮询获取验证码 GET /api/emails?mailbox=xxx"""
|
||||
for _ in range(max_attempts):
|
||||
if debug:
|
||||
print(f"[DEBUG] 开始轮询获取验证码,邮箱: {email}")
|
||||
for i in range(max_attempts):
|
||||
try:
|
||||
if debug:
|
||||
print(f"[DEBUG] 第 {i+1}/{max_attempts} 次轮询...")
|
||||
res = requests.get(
|
||||
f"{self.base_url}/api/emails",
|
||||
params={"mailbox": email},
|
||||
headers=self.headers,
|
||||
timeout=10
|
||||
)
|
||||
if debug:
|
||||
print(f"[DEBUG] 响应状态: {res.status_code}")
|
||||
if res.status_code == 200:
|
||||
emails = res.json()
|
||||
if emails and emails[0].get("verification_code"):
|
||||
code = emails[0]["verification_code"]
|
||||
return code.replace("-", "")
|
||||
except:
|
||||
pass
|
||||
if debug:
|
||||
print(f"[DEBUG] 响应数据: {emails}")
|
||||
if emails and len(emails) > 0:
|
||||
# 检查邮件字段
|
||||
first_email = emails[0]
|
||||
if debug:
|
||||
print(f"[DEBUG] 第一封邮件字段: {first_email.keys()}")
|
||||
# 可能的验证码字段名
|
||||
code = first_email.get("verification_code") or first_email.get("code") or first_email.get("verify_code")
|
||||
if code:
|
||||
if debug:
|
||||
print(f"[DEBUG] 获取到验证码: {code}")
|
||||
return code.replace("-", "")
|
||||
else:
|
||||
# 从 subject 提取验证码(格式: "XXX-XXX xAI confirmation code")
|
||||
subject = first_email.get("subject", "")
|
||||
if debug:
|
||||
print(f"[DEBUG] Subject: {subject}")
|
||||
# 提取前 7 位(含横杠)或匹配 XXX-XXX 模式
|
||||
import re
|
||||
match = re.search(r'^([A-Z0-9]{3}-[A-Z0-9]{3})', subject)
|
||||
if match:
|
||||
code = match.group(1)
|
||||
if debug:
|
||||
print(f"[DEBUG] 从 Subject 提取验证码: {code}")
|
||||
return code.replace("-", "")
|
||||
except Exception as e:
|
||||
if debug:
|
||||
print(f"[DEBUG] 轮询异常: {e}")
|
||||
time.sleep(1)
|
||||
if debug:
|
||||
print(f"[DEBUG] 轮询结束,未获取到验证码")
|
||||
return None
|
||||
|
||||
def delete_email(self, address):
|
||||
|
||||
Reference in New Issue
Block a user