Cloud Functions for Firebase - getaddrinfo ENOTFOUND

Cloud Functions for Firebase - getaddrinfo ENOTFOUND

正在尝试使用 PayPal-node-SDK

向 Paypal 的 API 发出请求
exports.requestPayment = functions.https.onRequest((req, res) => {
    return new Promise(function (fullfilled, rejected) {
        paypal.payment.create(create_payment_json, {}, function (error, payment) {
            if (error) {
                rejected(error);
            } else {
                console.log("Create Payment Response");
                console.log(payment);
                res.status(200).send(JSON.stringify({
                    paymentID: payment.id
                })).end();
                fullfilled(payment);
            }
        });
     });
});

但我经常收到错误消息:

Error: getaddrinfo ENOTFOUND api.sandbox.paypal.com api.sandbox.paypal.com:443
    at errnoException (dns.js:28:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)

我尝试过的事情:

  1. 向完全不同的主机发出请求,仍然ENOTFOUND
  2. cors(req,res, ()=>{...})
  3. 包装请求
  4. 在主机前 https://

问题是什么?

您需要使用付费套餐才能发出外部 API 请求。

Firebase 的 Blaze 计划(即付即用)为 Cloud Functions 提供免费配额。 https://firebase.google.com/pricing/

您需要将服务帐户包含到管理员初始化中。这为我解决了同样的问题

在我的情况下,我不得不等待,让发生的延迟过去。现在又好了。

切换到 Firebase "Blaze" 计划,其中包括 free usage tier of the Spark plan before incurring any costs. Use the Blaze pricing calculator 以查看给定使用量的费用。

出站(出站)网络的前 5GB 免费,与 "native" Google Cloud Functions would give you.

相同

我遇到这个问题是因为网络信号弱,请更改网络连接。