对 https API 的 IBM Web 操作调用不起作用
IBM web action call to https API not working
我正在使用 IBM Watson 创建一个助手。助手正在将一些信息传递给调用 https API 的 Web 操作,并以 JSON 格式将数据取回助手。
看起来网络操作只是在工作,偶尔会弹出一条消息 "error: The action did not produce a valid response and exited unexpectedly."。目前尚不清楚何时或什么触发了故障。在几秒钟内多次调用完全相同的操作会导致错误消息随机出现(我没有更改调用之间的操作或代码中的任何内容)。如果没有错误,代码将完美运行并提供预期的答案。
这里是压缩代码:
function main(msg){
const https = require('https');
var reqUrl = https URL;
return new Promise(function(resolve, reject) {
https.get(reqUrl, (responseFromAPI) => {
responseFromAPI.on('data', (chunk) => {
completeResponse += chunk;
let movie_info = JSON.parse(completeResponse);
movie_info = movie_info.results[0];
console.log(movie_info);
resolve({movie_info});
})
responseFromAPI.on('error', (error) => {
console.log(error);
reject(error);
});
});
});
}
错误日志如下:
[
“2019-06-06T14:35:32.697875Z 标准错误:undefined:1”,
“2019-06-06T14:35:32.697909Z 标准错误:{\"page\":1,\"total_results\":76,\"total_pages\":4,\"results\":[{ \"vote_count\":39,\"id\":541560,\"video\":false,\"vote_average\":5,\"title\":\"The Wind\", \"popularity\":37.299,\"poster_path\":\"\/kcfPHZHSQODLCWdkUVLYATNyEVo.jpg\",\"original_language\":\"en\",\"original_title\":\ "The Wind\",\"genre_ids\":[27,37,53],\"backdrop_path\":\"\/bqi6QBbXmkBar98HJJKEV1HFx71.jpg\",\"adult\":false,\ "overview\":\"A supernatural thriller set in the Western frontier of the late 1800s, The Wind stars Caitlin Gerard as a plains-woman driven mad by the harshness and isolation of the untamed land.\",\"release_date\":\"2019-06-06\"},{\"vote_count\":2832,\"id\":353491, \"video\":false,\"vote_average\":5.6,\"title\":\"The Dark Tower\",\"popularity\":18.474,\"poster_path\":\" \/i9GUSgddIqrroubiLsvvMRYyRy0.jpg\",\"original_language\":\"en\",\"original_title\":\"The Dark Tower\",\"genre_ids\":[28,14,878, 37,27],\"backdrop_path\":\"\/pVVobDO8cezhVPvwD6EBUN0g3mt.jpg\",\"adult\":false,\"overview\":\"The last Gunslinger, Roland Deschain, has been locked in an eternal battle with Walter O’Dim, also known as the",
“2019-06-06T14:35:32.697914Z 标准错误:”,
“2019-06-06T14:35:32.697951Z 标准错误:语法错误:JSON 输入意外结束”,
“2019-06-06T14:35:32.697955Z 标准错误:在 JSON.parse ()”,
“2019-06-06T14:35:32.697959Z 标准错误:在 IncomingMessage.responseFromAPI.on(在 NodeActionRunner.init 处评估(/nodejsAction/runner.js:79:45),:10:38)”,
“2019-06-06T14:35:32.697963Z 标准错误:在 IncomingMessage.emit (events.js:189:13)”,
“2019-06-06T14:35:32.697968Z 标准错误:在 IncomingMessage.Readable.read (_stream_readable.js:487:10)”,
“2019-06-06T14:35:32.697972Z stderr: 在流动 (_stream_readable.js:931:34)”,
“2019-06-06T14:35:32.697976Z 标准错误:在 resume_ (_stream_readable.js:912:3)”,
“2019-06-06T14:35:32.697980Z 标准错误:在 process._tickCallback (internal/process/next_tick.js:63:19)”,
"unknown unknown: There was an issue while collecting your logs. Data might be missing."
]
movie_info 是电影和数据的列表,因此代码只获取位置 [0] 中的数据(这里是电影 "The wind")。
我联系了 API 主机,他们说 API 工作正常,因此问题可能来自网络操作本身。
感谢任何帮助。
您没有解析所有响应,只解析了第一个块
function main(msg){
const https = require('https');
var reqUrl = https URL;
return new Promise(function(resolve, reject) {
https.get(reqUrl, (responseFromAPI) => {
const chunks = [];
responseFromAPI
.on('data', chunk => chunks.push(chunk))
.on('end', _=> {
let movie_info = JSON.parse(Buffer.concat(chunks));
movie_info = movie_info.results[0];
console.log(movie_info);
resolve({movie_info});
})
.on('error', (error) => {
console.log(error);
reject(error);
});
});
});
}
我正在使用 IBM Watson 创建一个助手。助手正在将一些信息传递给调用 https API 的 Web 操作,并以 JSON 格式将数据取回助手。
看起来网络操作只是在工作,偶尔会弹出一条消息 "error: The action did not produce a valid response and exited unexpectedly."。目前尚不清楚何时或什么触发了故障。在几秒钟内多次调用完全相同的操作会导致错误消息随机出现(我没有更改调用之间的操作或代码中的任何内容)。如果没有错误,代码将完美运行并提供预期的答案。
这里是压缩代码:
function main(msg){
const https = require('https');
var reqUrl = https URL;
return new Promise(function(resolve, reject) {
https.get(reqUrl, (responseFromAPI) => {
responseFromAPI.on('data', (chunk) => {
completeResponse += chunk;
let movie_info = JSON.parse(completeResponse);
movie_info = movie_info.results[0];
console.log(movie_info);
resolve({movie_info});
})
responseFromAPI.on('error', (error) => {
console.log(error);
reject(error);
});
});
});
}
错误日志如下:
[ “2019-06-06T14:35:32.697875Z 标准错误:undefined:1”, “2019-06-06T14:35:32.697909Z 标准错误:{\"page\":1,\"total_results\":76,\"total_pages\":4,\"results\":[{ \"vote_count\":39,\"id\":541560,\"video\":false,\"vote_average\":5,\"title\":\"The Wind\", \"popularity\":37.299,\"poster_path\":\"\/kcfPHZHSQODLCWdkUVLYATNyEVo.jpg\",\"original_language\":\"en\",\"original_title\":\ "The Wind\",\"genre_ids\":[27,37,53],\"backdrop_path\":\"\/bqi6QBbXmkBar98HJJKEV1HFx71.jpg\",\"adult\":false,\ "overview\":\"A supernatural thriller set in the Western frontier of the late 1800s, The Wind stars Caitlin Gerard as a plains-woman driven mad by the harshness and isolation of the untamed land.\",\"release_date\":\"2019-06-06\"},{\"vote_count\":2832,\"id\":353491, \"video\":false,\"vote_average\":5.6,\"title\":\"The Dark Tower\",\"popularity\":18.474,\"poster_path\":\" \/i9GUSgddIqrroubiLsvvMRYyRy0.jpg\",\"original_language\":\"en\",\"original_title\":\"The Dark Tower\",\"genre_ids\":[28,14,878, 37,27],\"backdrop_path\":\"\/pVVobDO8cezhVPvwD6EBUN0g3mt.jpg\",\"adult\":false,\"overview\":\"The last Gunslinger, Roland Deschain, has been locked in an eternal battle with Walter O’Dim, also known as the", “2019-06-06T14:35:32.697914Z 标准错误:”, “2019-06-06T14:35:32.697951Z 标准错误:语法错误:JSON 输入意外结束”, “2019-06-06T14:35:32.697955Z 标准错误:在 JSON.parse ()”, “2019-06-06T14:35:32.697959Z 标准错误:在 IncomingMessage.responseFromAPI.on(在 NodeActionRunner.init 处评估(/nodejsAction/runner.js:79:45),:10:38)”, “2019-06-06T14:35:32.697963Z 标准错误:在 IncomingMessage.emit (events.js:189:13)”, “2019-06-06T14:35:32.697968Z 标准错误:在 IncomingMessage.Readable.read (_stream_readable.js:487:10)”, “2019-06-06T14:35:32.697972Z stderr: 在流动 (_stream_readable.js:931:34)”, “2019-06-06T14:35:32.697976Z 标准错误:在 resume_ (_stream_readable.js:912:3)”, “2019-06-06T14:35:32.697980Z 标准错误:在 process._tickCallback (internal/process/next_tick.js:63:19)”, "unknown unknown: There was an issue while collecting your logs. Data might be missing." ]
movie_info 是电影和数据的列表,因此代码只获取位置 [0] 中的数据(这里是电影 "The wind")。
我联系了 API 主机,他们说 API 工作正常,因此问题可能来自网络操作本身。
感谢任何帮助。
您没有解析所有响应,只解析了第一个块
function main(msg){
const https = require('https');
var reqUrl = https URL;
return new Promise(function(resolve, reject) {
https.get(reqUrl, (responseFromAPI) => {
const chunks = [];
responseFromAPI
.on('data', chunk => chunks.push(chunk))
.on('end', _=> {
let movie_info = JSON.parse(Buffer.concat(chunks));
movie_info = movie_info.results[0];
console.log(movie_info);
resolve({movie_info});
})
.on('error', (error) => {
console.log(error);
reject(error);
});
});
});
}