Skip to content

Commit

Permalink
fix: #10
Browse files Browse the repository at this point in the history
  • Loading branch information
NanmiCoder committed Dec 15, 2023
1 parent 40cbd9f commit f85fd97
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions config/base_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
# 重试时间
RETRY_INTERVAL = 60 * 30 # 30 minutes

# playwright headless
HEADLESS = True
# 无头浏览器的标识,True:开启 False 关闭(会打开一个浏览器)
HEADLESS = False

# 是否保存登录状态
SAVE_LOGIN_STATE = True
Expand Down
8 changes: 6 additions & 2 deletions media_platform/xhs/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ def __init__(self,
self.login_phone = login_phone
self.cookie_str = cookie_str

@retry(stop=stop_after_attempt(20), wait=wait_fixed(1), retry=retry_if_result(lambda value: value is False))
@retry(stop=stop_after_attempt(120), wait=wait_fixed(1), retry=retry_if_result(lambda value: value is False))
async def check_login_state(self, no_logged_in_session: str) -> bool:
"""
Check if the current login status is successful and return True otherwise return False
retry decorator will retry 20 times if the return value is False, and the retry interval is 1 second
if max retry times reached, raise RetryError
"""

if "请通过验证" in await self.context_page.content():
utils.logger.info("登录过程中出现验证码,请手动验证")

current_cookie = await self.browser_context.cookies()
_, cookie_dict = utils.convert_cookies(current_cookie)
current_web_session = cookie_dict.get("web_session")
Expand Down Expand Up @@ -157,7 +161,7 @@ async def login_by_qrcode(self):
partial_show_qrcode = functools.partial(utils.show_qrcode, base64_qrcode_img)
asyncio.get_running_loop().run_in_executor(executor=None, func=partial_show_qrcode)

utils.logger.info(f"waiting for scan code login, remaining time is 20s")
utils.logger.info(f"waiting for scan code login, remaining time is 120s")
try:
await self.check_login_state(no_logged_in_session)
except RetryError:
Expand Down

0 comments on commit f85fd97

Please sign in to comment.