From 1341b60c4e2ce56d3e7858e29987b97edcb372b7 Mon Sep 17 00:00:00 2001 From: Evil0ctal Date: Sun, 26 May 2024 18:03:15 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8:=20Fix=20TikTok=20Web=20msToken=20?= =?UTF-8?q?code=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crawlers/tiktok/web/config.yaml | 2 +- crawlers/tiktok/web/utils.py | 9 +++------ crawlers/tiktok/web/web_crawler.py | 8 ++++---- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/crawlers/tiktok/web/config.yaml b/crawlers/tiktok/web/config.yaml index 0d333b8..c3016fb 100644 --- a/crawlers/tiktok/web/config.yaml +++ b/crawlers/tiktok/web/config.yaml @@ -10,7 +10,7 @@ TokenManager: https: msToken: - url: https://mssdk-sg.tiktok.com/web/common?msToken=1Ab-7YxR9lUHSem0PraI_XzdKmpHb6j50L8AaXLAd2aWTdoJCYLfX_67rVQFE4UwwHVHmyG_NfIipqrlLT3kCXps-5PYlNAqtdwEg7TrDyTAfCKyBrOLmhMUjB55oW8SPZ4_EkNxNFUdV7MquA== + url: https://mssdk.tiktokw.us/web/report?msToken=1Ab-7YxR9lUHSem0PraI_XzdKmpHb6j50L8AaXLAd2aWTdoJCYLfX_67rVQFE4UwwHVHmyG_NfIipqrlLT3kCXps-5PYlNAqtdwEg7TrDyTAfCKyBrOLmhMUjB55oW8SPZ4_EkNxNFUdV7MquA== magic: 538969122 version: 1 dataType: 8 diff --git a/crawlers/tiktok/web/utils.py b/crawlers/tiktok/web/utils.py index 8212727..a53fd76 100644 --- a/crawlers/tiktok/web/utils.py +++ b/crawlers/tiktok/web/utils.py @@ -76,9 +76,6 @@ class TokenManager: msToken = str(httpx.Cookies(response.cookies).get("msToken")) - if len(msToken) not in [148]: - raise APIResponseError("{0} 内容不符合要求".format("msToken")) - return msToken # except httpx.RequestError as exc: @@ -90,7 +87,7 @@ class TokenManager: # except httpx.HTTPStatusError as e: # # 捕获 httpx 的状态代码错误 (captures specific status code errors from httpx) # if response.status_code == 401: - # raise APIUnauthorizedError("参数验证失败,请更新 F2 配置文件中的 {0},以匹配 {1} 新规则" + # raise APIUnauthorizedError("参数验证失败,请更新 Douyin_TikTok_Download_API 配置文件中的 {0},以匹配 {1} 新规则" # .format("msToken", "tiktok") # ) # @@ -151,7 +148,7 @@ class TokenManager: except httpx.HTTPStatusError as e: # 捕获 httpx 的状态代码错误 (captures specific status code errors from httpx) if response.status_code == 401: - raise APIUnauthorizedError("参数验证失败,请更新 F2 配置文件中的 {0},以匹配 {1} 新规则" + raise APIUnauthorizedError("参数验证失败,请更新 Douyin_TikTok_Download_API 配置文件中的 {0},以匹配 {1} 新规则" .format("ttwid", "tiktok") ) @@ -190,7 +187,7 @@ class TokenManager: except httpx.HTTPStatusError as e: # 捕获 httpx 的状态代码错误 (captures specific status code errors from httpx) if response.status_code == 401: - raise APIUnauthorizedError("参数验证失败,请更新 F2 配置文件中的 {0},以匹配 {1} 新规则" + raise APIUnauthorizedError("参数验证失败,请更新 Douyin_TikTok_Download_API 配置文件中的 {0},以匹配 {1} 新规则" .format("odin_tt", "tiktok") ) diff --git a/crawlers/tiktok/web/web_crawler.py b/crawlers/tiktok/web/web_crawler.py index 8fd2b37..ce293a3 100644 --- a/crawlers/tiktok/web/web_crawler.py +++ b/crawlers/tiktok/web/web_crawler.py @@ -348,10 +348,10 @@ class TikTokWebCrawler: # print(response) # 获取用户的个人信息 - # secUid = "MS4wLjABAAAAfDPs6wbpBcMMb85xkvDGdyyyVAUS2YoVCT9P6WQ1bpuwEuPhL9eFtTmGvxw1lT2C" - # uniqueId = "c4shjaz" - # response = await self.fetch_user_profile(secUid, uniqueId) - # print(response) + secUid = "MS4wLjABAAAAfDPs6wbpBcMMb85xkvDGdyyyVAUS2YoVCT9P6WQ1bpuwEuPhL9eFtTmGvxw1lT2C" + uniqueId = "c4shjaz" + response = await self.fetch_user_profile(secUid, uniqueId) + print(response) # 获取用户的作品列表 # secUid = "MS4wLjABAAAAfDPs6wbpBcMMb85xkvDGdyyyVAUS2YoVCT9P6WQ1bpuwEuPhL9eFtTmGvxw1lT2C"