调用云函数出错
- 当前 Bug 的表现(可附上截图) - 预期表现 - 复现路径 - 提供一个最简复现 Demo 偶现调用云函数出错,错误如下图。出错后再重复调用几次又能正常调用,直接对云函数进行测试,并没有发现异常。 [图片] 以下是云函数的代码 [代码]const https = require([代码][代码]'https'[代码][代码]);[代码] [代码]cloud.init()[代码] [代码]// 云函数入口函数[代码][代码]exports.main = async (event, context) => {[代码][代码] [代码][代码]console.log(event);[代码][代码] [代码][代码]console.log(context);[代码] [代码] [代码][代码]let result = await getAnimal(event.imgbase64);[代码][代码] [代码][代码]console.log(result);[代码][代码] [代码][代码]return[代码] [代码]{ result };[代码][代码]}[代码] [代码]function[代码] [代码]getAnimal(imgbase64) {[代码][代码] [代码][代码]return[代码] [代码]new[代码] [代码]Promise((resolve, reject) => {[代码][代码] [代码][代码]var[代码] [代码]accessToken =[代码][代码]'[代码]24.e3bb433cd200255ac99826a61b9e9d52.2592000.1554562978.282335-15699423 [代码]'[代码][代码]; [代码][代码] [代码][代码]let postData = qs.stringify( {[代码][代码] [代码][代码]image: imgbase64,[代码][代码] [代码][代码]baike_num: [代码][代码]"1"[代码][代码] [代码][代码]});[代码][代码] [代码][代码]let options = {[代码][代码] [代码][代码]hostname: [代码][代码]'aip.baidubce.com'[代码][代码],[代码][代码] [代码][代码]path: [代码][代码]'/rest/2.0/image-classify/v1/animal?access_token='[代码] [代码]+ accessToken,[代码][代码] [代码][代码]method: [代码][代码]'POST'[代码][代码],[代码][代码] [代码][代码]headers: {[代码][代码] [代码][代码]'Content-Type'[代码][代码]: [代码][代码]'application/x-www-form-urlencoded'[代码][代码] [代码][代码]}[代码][代码] [代码][代码]}[代码][代码] [代码][代码]let req = https.request(options,[代码][代码] [代码][代码]function[代码] [代码](res) {[代码][代码] [代码][代码]res.on([代码][代码]'data'[代码][代码], (data) => {[代码][代码] [代码][代码]resolve(JSON.parse(data.toString()));[代码][代码] [代码][代码]});[代码][代码] [代码][代码]res.on([代码][代码]'error'[代码][代码], (err)=>{[代码][代码] [代码][代码]reject(err);[代码][代码] [代码][代码]});[代码][代码] [代码][代码]}[代码][代码] [代码][代码]);[代码][代码] [代码][代码]req.write(postData);[代码][代码] [代码][代码]req.end();[代码][代码] [代码][代码]});[代码][代码]}[代码]