收藏
回答

云函数 DescribeProducts 调用失败,不知为何?

代码

// Depends on tencentcloud-sdk-nodejs version 4.0.3 or higher
const tencentcloud = require("tencentcloud-sdk-nodejs");

const IotcloudClient = tencentcloud.iotcloud.v20180614.Client;

exports.main = async (event, context) => {

  const clientConfig = {
    credential: {
      SecretId: event.secretId,
      SecretKey: event.secretKey,
    },
    region: "",
    profile: {
      httpProfile: {
        endpoint: "iotcloud.tencentcloudapi.com",
      },
    },
  };

  console.log(event)

  const client = new IotcloudClient(clientConfig);

  console.log(client)

  const params = {};
 
  const retval = client.DescribeProducts(params);

  console.log(retval)

  return retval;
  client.DescribeProducts(params).then(
    (data) => {
      console.log(data);
      /*
      return{
        success: true,
        data: data
      }
      */
    },
    (err) => {
      console.error("error", err);
      /*
      return{
        success: false,
        err: err
      }
      */
    }
  );
}

日志

START
{
  "SecretId": "正确的ID",
  "SecretKey": "正确的key",
  "type": "iotcloud_describeProducts",
  "userInfo": {
    "appId": "xxxxxxxxxxx",
    "openId": "xxxxxxxxxxx"
  }
}
{
  "apiVersion": "2018-06-14",
  "credential": {
    "credential": {},
    "profile": {
      "httpProfile": {
        "endpoint": "iotcloud.tencentcloudapi.com"
      }
    },
    "region": ""
  },
  "endpoint": "iotcloud.tencentcloudapi.com",
  "path": "/",
  "profile": {
    "httpProfile": {
      "endpoint": null,
      "protocol": "https://",
      "reqMethod": "POST",
      "reqTimeout": 60
    },
    "signMethod": "xxxxxxxxxxx"
  },
  "region": null,
  "sdkVersion": "SDK_NODEJS_3.0.104"
}

(node:7) UnhandledPromiseRejectionWarning: TypeError: cb is not a function
    at IotcloudClient.failRequest (/var/lang/node10/lib/node_modules/tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client.js:65:9)
    at doRequest.then.error (/var/lang/node10/lib/node_modules/tencentcloud-sdk-nodejs/tencentcloud/common/abstract_client.js:72:98)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 3)
REPORT RequestId:863720f9-dfb5-11eb-ad4b-5254000505e4 Duration:36ms Memory:256MB MemUsage:141.890625MB
END

不知道原因

最后一次编辑于  2021-07-08
回答关注问题邀请回答
收藏

1 个回答

  • xplee
    xplee
    2021-07-08

    tencentcloud-sdk-nodejs 换个版本试试


    2021-07-08
    有用
    回复 5
    • 爱上思念
      爱上思念
      2021-07-08
      请问如何换云端的sdk版本
      2021-07-08
      回复
    • xplee
      xplee
      2021-07-08回复爱上思念
      https://cloud.tencent.com/document/sdk/Node.js
      2021-07-08
      回复
    • 爱上思念
      爱上思念
      2021-07-08
      您的意思是将源代码做为云函数上传到云吗?
      2021-07-08
      回复
    • xplee
      xplee
      2021-07-08回复爱上思念
      是的,或者修改云函数目录下的一个package.json文件里面去指定依赖的版本,然后再执行npm install
      2021-07-08
      回复
    • 爱上思念
      爱上思念
      2021-07-09
      懂了,谢谢
      2021-07-09
      回复
登录 后发表内容