From 21c48473a03c2775c2ddd8c285f0daab3f336288 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B2=9B=E9=A3=8E?= Date: Tue, 17 Sep 2019 01:26:17 +0800 Subject: [PATCH] fix waring or bug --- Pixiv.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Pixiv.py b/Pixiv.py index bc29cf8..2bb9056 100644 --- a/Pixiv.py +++ b/Pixiv.py @@ -11,12 +11,15 @@ import os try: import requests import redis + except: print('检测到缺少必要包!正在尝试安装!.....') os.system(r'pip install -r requirements.txt') import requests import redis +requests.packages.urllib3.disable_warnings() + class PixivSpider(object): @@ -26,7 +29,7 @@ class PixivSpider(object): self.r = redis.Redis(host='localhost', port=6379, decode_responses=True) def get_list(self, pid): - response = requests.get(self.ajax_url.format(pid), headers=self.headers) + response = requests.get(self.ajax_url.format(pid), headers=self.headers, verify=False) json_data = response.json() list_temp = json_data['body'] for l in list_temp: @@ -52,7 +55,7 @@ class PixivSpider(object): t = 0 while t < 3: try: - img_temp = requests.get(url, headers=self.headers, timeout=15) + img_temp = requests.get(url, headers=self.headers, timeout=15, verify=False) break except requests.exceptions.ConnectTimeout: print("连接超时!正在重试!") @@ -67,7 +70,7 @@ class PixivSpider(object): 'p': f'{num}', 'format': 'json' } - response = requests.get(self.top_url, params=params, headers=self.headers) + response = requests.get(self.top_url, params=params, headers=self.headers, verify=False) json_data = response.json() self.pixiv_spider_go(json_data['contents'])