本文介绍了云函数伪造者错误:位于http://www.google.com的net :: ERR_NAME_RESOLUTION_FAILED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Google Cloud Functions中,当我尝试使用puppeteer时,我尝试的所有网站都收到以下错误,例如google.com:
On google Cloud Functions when I try to use puppeteer I get the following error for all sites that I try, an example for google.com:
Error: net::ERR_NAME_RESOLUTION_FAILED at http://www.google.com
at navigate (/srv/node_modules/puppeteer/lib/FrameManager.js:101:37)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
-- ASYNC --
at Frame.<anonymous> (/srv/node_modules/puppeteer/lib/helper.js:110:27)
at Page.goto (/srv/node_modules/puppeteer/lib/Page.js:656:49)
at Page.<anonymous> (/srv/node_modules/puppeteer/lib/helper.js:111:23)
at /srv/index.js:35:20
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
云功能代码:
const functions = require("firebase-functions");
const cors = require("cors")({origin: true});
const Firestore = require("@google-cloud/firestore");
const puppeteer = require("puppeteer");
const cheerio = require("cheerio");
exports.getSiteOne = functions
.runWith({ memory: "2GB" })
.https.onRequest((req, res) => {
cors(req, res, async function() {
try {
const browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox"]
});
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3419.0 Safari/537.36');
await page.goto("http://www.google.com", {
waitUntil: "networkidle0"
});
var html = await page.content();
res.status(200).json({
message: "cron added",
html
});
}
catch (err) {
console.log(err);
res.status(500).json({
error: err
});
}
});
});
木偶版本"^ 1.14.0"
puppeteer version "^1.14.0"
注意:当我在本地提供服务时,效果很好
NB: when I serve it locally it works fine
推荐答案
该错误表明DNS查找失败.我假设您正在使用免费的火花计划" .那是不允许任何传出流量:
The error is saying that the DNS lookup fails. I'm assuming you are on the free "Spark Plan". That one is not allowing any outgoing traffic:
这篇关于云函数伪造者错误:位于http://www.google.com的net :: ERR_NAME_RESOLUTION_FAILED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!