kuwoMusicApi
kuwoMusicApi copied to clipboard
请求接口的时候会随机崩溃
每次请求接口都有一定概率崩溃,信息如下
nodejs.JSONResponseFormatError: Unexpected token E in JSON at position 0 (data json format: "Error occured while trying to proxy to: www.kuwo.cn/api/www/bang/bang/musicList?bangId=12&pn=1&rn=50&httpsStatus=1&reqId=cd177cbe-88de-42ca-9137-24060680b175"), GET http://www.kuwo.cn/api/www/bang/bang/musicList?bangId=12&pn=1&rn=50&httpsStatus=1&reqId=cd177cbe-88de-42ca-9137-24060680b175 504 (connected: true, keepalive socket: false, agent status: {"createSocketCount":249,"createSocketErrorCount":0,"closeSocketCount":248,"errorSocketCount":0,"timeoutSocketCount":247,"requestCount":401,"freeSockets":{},"sockets":{"www.kuwo.cn:80:":1},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 1)
headers: {"server":"nginx","date":"Sun, 27 Feb 2022 14:38:35 GMT","content-type":"application/json; charset=utf-8","content-length":"157","connection":"keep-alive","set-cookie":["kw_token=SVJFKJ3RR68; path=/; expires=Tue, 29 Mar 2022 14:38:34 GMT"],"vary":"Accept-Encoding"}
headers: {"server":"nginx","date":"Sun, 27 Feb 2022 14:38:35 GMT","content-type":"application/json; charset=utf-8","content-length":"157","connection":"keep-alive","set-cookie":["kw_token=SVJFKJ3RR68; path=/; expires=Tue, 29 Mar 2022 14:38:34 GMT"],"vary":"Accept-Encoding"}
at JSON.parse (
应该是访问过快返回504了,这时候应该等约1秒再访问一次,访问个3~4次就成功了。
这玩意,酷我官网都是这样,不清楚是咋回事,刷着刷着接口就挂了
---原始邮件--- 发件人: @.> 发送时间: 2023年1月18日(周三) 上午10:56 收件人: @.>; 抄送: @.***>; 主题: Re: [QiuYaohong/kuwoMusicApi] 请求接口的时候会随机崩溃 (Issue #6)
应该是访问过快返回504了,这时候应该等约1秒再访问一次,访问个3~4次就成功了。
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.***>
加个 try catch包在外面可能就可以了(指仓库代码)。
这玩意,酷我官网都是这样,不清楚是咋回事,刷着刷着接口就挂了 … ---原始邮件--- 发件人: @.> 发送时间: 2023年1月18日(周三) 上午10:56 收件人: @.>; 抄送: @.>; 主题: Re: [QiuYaohong/kuwoMusicApi] 请求接口的时候会随机崩溃 (Issue #6) 应该是访问过快返回504了,这时候应该等约1秒再访问一次,访问个3~4次就成功了。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.>
这是官方的保护机制。有概率访问504,我一般都是返回504后重新发送一次fetch请求。
这样的嘛,了解了居然还有这种扯淡的保护机制,我看看哪天重新整一下
---原始邮件--- 发件人: @.> 发送时间: 2023年1月18日(周三) 中午11:00 收件人: @.>; 抄送: @.@.>; 主题: Re: [QiuYaohong/kuwoMusicApi] 请求接口的时候会随机崩溃 (Issue #6)
这玩意,酷我官网都是这样,不清楚是咋回事,刷着刷着接口就挂了 … ---原始邮件--- 发件人: @.> 发送时间: 2023年1月18日(周三) 上午10:56 收件人: @.>; 抄送: @.>; 主题: Re: [QiuYaohong/kuwoMusicApi] 请求接口的时候会随机崩溃 (Issue #6) 应该是访问过快返回504了,这时候应该等约1秒再访问一次,访问个3~4次就成功了。 — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you are subscribed to this thread.Message ID: @.>
这是官方的保护机制。有概率访问504,我一般都是返回504后重新发送一次fetch请求。
— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>
这是我用 request 实现的一个请求方法,您可以参考下。 URL:访问网址、Header:请求头 Refunc:返回的函数,返回信息后将会调用这个函数 Otherc:在调用返回函数额外的参数(除了data外)
function fetchinfo(url, headers, recfunc, otherc) {
const options = {
url: url,
headers: headers
};
function callback(error, response, body) {
if (!error && response.statusCode == 200) {
try {
recfunc(JSON.parse(body), otherc);
return;
} catch (e) {
}
recfunc(body, otherc);
return;
// const info = JSON.parse(body);
// console.log(info.stargazers_count + " Stars");
// console.log(info.forks_count + " Forks");
} else {
recfunc(body, otherc);
}
}
request(options, callback);
});
我这边是直接将错误返回给前端,让前端来处理。 避免后端处理错误直接崩溃。