From c0ffd669018944d0964a1a60ac338d149ce3963f Mon Sep 17 00:00:00 2001 From: josedelinux <37724086+josedelinux@users.noreply.github.com> Date: Fri, 9 Jul 2021 10:41:58 +0800 Subject: [PATCH] Update api.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 下载过程中或有error: Return {'msg': '操作频繁,请稍候再试', 'code': 406, 'message': '操作频繁,请稍候再试'} when try to get http://music.163.com/api/song/detail/?ids=[40638xxxxx] 添加了sleep延时20秒 --- ncm/api.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ncm/api.py b/ncm/api.py index 3ce80f1..fe2fed9 100644 --- a/ncm/api.py +++ b/ncm/api.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import requests +import time from ncm.encrypt import encrypted_request from ncm.constants import headers @@ -23,7 +24,12 @@ class CloudApi(object): response = self.session.get(url, timeout=self.timeout) result = response.json() - if result['code'] != 200: + if result['code'] == 406: + print("Busy! retry after 20 seconds") + time.sleep(20) + response = self.session.get(url, timeout=self.timeout) + result = response.json() + if result['code'] != 200 and result['code'] !=406: print('Return {} when try to get {}'.format(result, url)) else: return result