We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
search
试着把 KuWoApi 的代码剥离出来,然后直接调用 search() 方法,但是仍然无法得到数据:
KuWoApi
search()
from hashlib import md5, sha1, sha256 import requests class KuwoApi: """ kuwo music API class """ API_BASE: str = 'http://www.kuwo.cn/api/www' def __init__(self): """ class initializer """ self.timeout = 30 self.headers = { 'Accept': '*/*', 'Accept-Encoding': 'gzip,deflate', 'Accept-Language': 'zh-CN,zh;q=0.8,gl;q=0.6,zh-TW;q=0.4', 'Referer': 'http://kuwo.cn', 'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) ' 'Chrome/81.0.4044.138 Safari/537.36', 'Host': 'kuwo.cn', } self.mobi_headers = {'User-Agent': 'okhttp/3.10.0'} # 网络请求中的值,发现 Cross 和 md5 算出来的不一样 # random_str = "BH4h5GXbY45H266eeACjWdNAzmE48iwy" # self.headers['Cross'] = "2eddd1c15545e43176876e4f142d4448" random_str = "123456789" self.headers['csrf'] = random_str self.cookie = {'kw_token': random_str, 'Hm_token': random_str} self.headers['Cross'] = md5(random_str.encode('utf-8')).hexdigest() self._userid = '' self._sid = '' self._cookies = {} def search(self, keyword: str, limit=20, page=1) -> dict: uri = KuwoApi.API_BASE + f'/search/searchMusicBykeyWord?key={keyword}&pn={page}&rn={limit}' with requests.Session() as session: response = session.get(uri, cookies=self.cookie, headers=self.headers) data = response.json() return data response = KuwoApi().search('Hello', 20, 1) print(response) # {'success': False, 'message': 'CSRF token Invalid!', 'now': '2023-07-14T15:00:49.148Z'}
The text was updated successfully, but these errors were encountered:
BruceZhang1993
No branches or pull requests
试着把
KuWoApi
的代码剥离出来,然后直接调用search()
方法,但是仍然无法得到数据:The text was updated successfully, but these errors were encountered: