node.js Firebase 云函数 - getaddrinfo ENOTFOUND

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42774807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:04:51  来源:igfitidea点击:

Cloud Functions for Firebase - getaddrinfo ENOTFOUND

node.jsfirebasepaypaldnsgoogle-cloud-functions

提问by user47376

Trying to make a request to Paypal's API using PayPal-node-SDK

尝试使用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);
            }
        });
     });
});

but I'm constantly getting an error:

但我不断收到错误消息:

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)

Things I've tried:

我尝试过的事情:

  1. Making a request to a totally different host, still ENOTFOUND
  2. Wrapping the request with cors(req,res, ()=>{...})
  3. Prepending https://to the host
  1. 向完全不同的主机发出请求,仍然 ENOTFOUND
  2. 包装请求 cors(req,res, ()=>{...})
  3. 准备https://到主机

What is the problem?

问题是什么?

回答by James Daniels

You'll need to be on a paid plan to make external API requests.

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

Firebase's Blaze plan (pay as you go) has a free allotment for Cloud Functions. https://firebase.google.com/pricing/

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

回答by Levi Winans

in my situation I had to wait and let what ever lag was happening pass. Now it's fine again.

在我的情况下,我不得不等待,让发生的任何滞后过去。现在又好了。

回答by kynan

Switch to the Firebase "Blaze" plan, which includes the free usage tier of the Spark planbefore incurring any costs. Use the Blaze pricing calculatorto see what you'd be charged for a given usage.

在产生任何费用之前,切换到 Firebase“Blaze”计划,其中包括Spark 计划免费使用层。使用Blaze 定价计算器查看您需要为特定使用量支付多少费用。

The first 5GB of outbound (egress) networking is free, which is the same as what "native" Google Cloud Functions would give you.

出站(出口)网络的前 5GB 是免费的,这与“原生”Google Cloud Functions为您提供的相同

回答by EngrEric

You need to include service account to the admin initialization. this fixed the same issue for me

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