From 708a4968c69cfc90974baca777b318e109dfa663 Mon Sep 17 00:00:00 2001 From: zjk2017 <2548836866@qq.com> Date: Thu, 22 Aug 2024 19:28:27 +0800 Subject: [PATCH] =?UTF-8?q?Update=20=E4=BA=A4=E6=B1=87=E7=82=B9.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 交汇点.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/交汇点.py b/交汇点.py index 4855f5b..aa2c44a 100644 --- a/交汇点.py +++ b/交汇点.py @@ -4,9 +4,8 @@ 抓任意包请求头 Authorization 变量名: JHD 部分报错不影响后续执行 偶尔报错正常 -cron: 3 7,12,18 * * * +cron: 39 7 * * * const $ = new Env("交汇点"); -原作者 xiaobu689 """ import os import random @@ -72,8 +71,15 @@ class JHD(): question = '' date_ = time.strftime("%Y-%m-%d", time.localtime()) url = f'https://jhd.xhby.net/activity/api/v1/story/exam-topic-infos/{date_}' - response = requests.get(url, headers=self.headers) - response_json = response.json() + + try: + response = requests.get(url, headers=self.headers) + response.raise_for_status() + response_json = response.json() + except requests.exceptions.RequestException as e: + print(f'请求daily_question接口失败: {e}') + # time.sleep(120) # 延迟120秒,‌即2分钟 + # self.daily_question() # 递归调用一次,‌重新尝试 if response_json['code'] == 0: uuid = response_json["data"]["uuid"] examId = response_json["data"]["examId"]