【问题标题】:Error trying to connect Google Earth Engine API in Node.js Server尝试在 Node.js 服务器中连接 Google Earth Engine API 时出错
【发布时间】:2021-10-25 23:05:54
【问题描述】:

我正在尝试开发一个 nodejs 应用程序,该应用程序使用 Google 地球引擎进行一些地理空间数据分析。我正在使用 "@google/earthengine": "^0.1.185"、节点 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

我真的需要你的帮助。

【问题讨论】:

  • signup了吗?
  • 是的,我做到了,它被证实了。我
  • 您是否使用此代码测试过安装:developers.google.com/earth-engine/guides/…
  • 是的@tttony,我尝试过但也遇到错误throw ee.initializationFailure_(e), e; ^ Error: Server returned HTTP code: 404
  • 我认为初始化中的错误。尝试使用this #1 哪个路由会抛出错误? / 或 /mapid #2 阅读this 及其示例后,我可以看到主要用于独立应用程序而不是服务器端。 #3 Map.addLayer 是什么?返回一个jpg? #4 你能先试试独立模式吗?如果可行,我可以帮助您在服务器端应用程序(快递)中使用它

标签: node.js google-maps google-cloud-platform google-earth-engine


【解决方案1】:

你的电脑好像连谷歌引擎服务服务器都联系不上。也许您应该尝试在另一台没有任何防火墙、代理或其他任何可能干扰您网络的计算机上测试您的代码。

另外,由于您在 İstanbul, Istambul, Turquia(偶尔是 interferes with Google services)中,因此请确保在您进行测试时 Google 地球引擎服务没有被阻止。如果您确定是这种情况,那么您可能需要代理或 vpn。或者,如果您使用的是代理/vpn,请确保代理/vpn 允许 google 引擎服务。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-28
    • 2023-03-29
    • 2023-03-03
    • 2022-01-20
    • 1970-01-01
    • 2016-12-03
    • 2020-01-07
    相关资源
    最近更新 更多