完善脚本
This commit is contained in:
1 parent
9d9509a26b
commit
0c740f5a53
9 files changed
+1176
-212
No files matched your search
+26
-6
@@ -51,7 +51,7 @@ class RegisterConfig:
|
||||
proxy: str = ""
|
||||
default_name: str = "John Doe"
|
||||
default_birthday: Dict[str, str] = field(default_factory=lambda: {"year": "1990", "month": "05", "day": "12"})
|
||||
impersonate: str = "chrome136"
|
||||
impersonate: str = "chrome"
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -69,13 +69,33 @@ class AccountRegister:
|
||||
self.config = config
|
||||
|
||||
def _log(self, step: str, status: str, message: str = ""):
|
||||
print(f"[register][{step}] {status}: {message}")
|
||||
# 某些托管/守护进程环境下 stdout 可能瞬时不可写(Errno 5),
|
||||
# 日志输出失败不应中断注册主流程。
|
||||
try:
|
||||
print(f"[register][{step}] {status}: {message}")
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
def _create_session(self) -> cffi_requests.Session:
|
||||
session = cffi_requests.Session(impersonate=self.config.impersonate)
|
||||
if self.config.proxy:
|
||||
session.proxies = {"http": self.config.proxy, "https": self.config.proxy}
|
||||
return session
|
||||
candidates = [self.config.impersonate, "chrome", "chrome120"]
|
||||
seen = set()
|
||||
last_error: Optional[Exception] = None
|
||||
for imp in candidates:
|
||||
if not imp or imp in seen:
|
||||
continue
|
||||
seen.add(imp)
|
||||
try:
|
||||
session = cffi_requests.Session(impersonate=imp)
|
||||
if self.config.proxy:
|
||||
session.proxies = {"http": self.config.proxy, "https": self.config.proxy}
|
||||
if imp != self.config.impersonate:
|
||||
self._log("session", "warn", f"impersonate 回退: {self.config.impersonate} -> {imp}")
|
||||
return session
|
||||
except Exception as e:
|
||||
last_error = e
|
||||
continue
|
||||
# 理论上不会到这里;若都失败,抛最后一个异常便于上层定位。
|
||||
raise last_error if last_error is not None else RuntimeError("session init failed")
|
||||
|
||||
def _api_headers(self, referer: str = "https://auth.openai.com/create-account") -> dict:
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user