gpt4 book ai didi

node.js - 尝试在 Node.js 服务器中连接 Google Earth Engine API 时出错

转载 作者:行者123 更新时间:2023-12-04 13:51:37 24 4
gpt4 key购买 nike

我正在尝试开发一个 nodejs 应用程序,该应用程序使用 Google 地球引擎进行一些地理空间数据分析。我正在使用 “@google/earthengine”:“^0.1.185”, Node v16.4.2 和 npm v 7.18.1。我还使用 gcloud 创建了服务帐户,并按照 Google Earth Engine npm installation 的逐步操作进行了操作。 .问题是,每次我调用一些地球引擎功能时,它只会给出错误:

throw ee.initializationFailure_(e), e;
^

Error: Failed to contact Earth Engine servers. Please check your connection, firewall, or browser extension settings
在我尝试连接到地球引擎时遇到 404 错误之前。我试图停用我的防火墙并更改我使用的互联网,但还是一样。
查看代码和错误:
const ee = require('@google/earthengine');
const path = require("path");
const express = require('express');
const app = express();
const privateKey = require('./privatekey.json');
const port = process.env.PORT || 4000;

app.set('views', __dirname + '/views');
//app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');

app.set("views", path.join(__dirname, "views"));
app.set("view engine", "html");


app.get('/', (_,res)=>{
res.sendFile('index.html', {root : __dirname + '/views'});
});
// Define endpoint at /mapid.
app.get('/mapid', (_, response) => {
// Instantiate an image with the Image constructor.
var image = ee.Image('CGIAR/SRTM90_V4');

// Zoom to a location.
Map.setCenter(-112.8598, 36.2841, 9); // Center on the Grand Canyon.

// Display the image on the map.
Map.addLayer(image);

});

console.log('Authenticating Earth Engine API using private key...');

ee.data.authenticateViaPrivateKey(
privateKey,
() => {
console.log('Authentication successful.');
ee.initialize(() => {
console.log('Earth Engine client library initialized.');
app.listen(port);
console.log(`Listening on port ${port}`);
},
(err) => {

console.log(err);

});

},
(err) => {

console.log(err);

});


app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
错误
C:\blablablabla\node_modules\@google\earthengine\build\main.js:17724
throw ee.initializationFailure_(e), e;
^

Error: Failed to contact Earth Engine servers. Please check your connection, firewall, or browser extension settings.
at Object.ee.data.handleResponse_ (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15467:9)
at Object.ee.data.send_ (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15390:18)
at Object.ee.data.getAlgorithms (C:\blablablabla\node_modules\@google\earthengine\build\main.js:14670:24)
at Function.ee.ApiFunction.initialize (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15923:78)
at Object.ee.initialize (C:\blablablabla\node_modules\@google\earthengine\build\main.js:17722:26)
at blablablabla\app.js:36:10
at Object.ee.data.handleAuthResult_ (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15497:16)
at blablablabla\node_modules\@google\earthengine\build\main.js:14490:19
at blablablabla\node_modules\@google\earthengine\build\main.js:14424:41
at blablablabla\node_modules\google-auth-library\lib\auth\jwtclient.js:119:5
请我真的需要你的帮助。

最佳答案

看来你的电脑连谷歌引擎服务服务器都联系不上。也许您应该尝试在另一台没有任何防火墙、代理或其他任何可能干扰您的网络的计算机上测试您的代码。
另外,由于您在 İstanbul, Istambul, Turquia , 其中 interferes with Google services偶尔,请确保在测试时未阻止 google earth 引擎服务。如果您确定是这种情况,那么您可能需要代理或 VPN。或者,如果您使用代理/vpn,请确保代理/vpn 允许谷歌引擎服务。

关于node.js - 尝试在 Node.js 服务器中连接 Google Earth Engine API 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68929166/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com