Google cloud platform @google云/存储:找不到具有指定主机名的服务器
即使在我的路径中提供了我的服务帐户密钥文件(xxx.json),我也无法连接Google cloud platform @google云/存储:找不到具有指定主机名的服务器,google-cloud-platform,google-cloud-storage,Google Cloud Platform,Google Cloud Storage,即使在我的路径中提供了我的服务帐户密钥文件(xxx.json),我也无法连接 const {Storage} = require('@google-cloud/storage'); const storage = new Storage(); const getTheStuff = async () => { try { const results = await storage.getBuckets(); const [buck
const {Storage} = require('@google-cloud/storage');
const storage = new Storage();
const getTheStuff = async () => {
try {
const results = await storage.getBuckets();
const [buckets] = results;
console.log('Buckets:');
buckets.forEach(bucket => {
console.log(bucket.name);
});
} catch (err) {
console.error('ERROR:', err);
}
}
我试着运行这个,但是我在控制台中得到了以下信息。我不确定是否发生了身份验证,我的配置是否有问题,或者完全是其他问题。看起来API被当作是从google cloud env运行的,因此无法连接到内部主机名,但是这个库可以在外部用于,所以我很困惑
[Error] A server with the specified hostname could not be found.
[Error] Fetch API cannot load http://metadata.google.internal./computeMetadata/v1/instance due to access control checks.
[Error] Failed to load resource: A server with the specified hostname could not be found. (instance, line 0)
[Log] Buckets: (main.chunk.js, line 83)
[Error] Failed to load resource: The request timed out. (instance, line 0)
你在哪里运行这个代码?此错误表示客户端库已检测到Google计算服务(计算引擎、云运行等),并且对元数据服务器的访问被禁用。如果您在计算引擎上运行,那么为实例分配了哪些作用域?我在本地开发机器上运行,而不是在google基础设施上运行。另外,我刚刚了解到node.js库不一定在浏览器环境中工作,我只是将代码移动到express.js,现在一切似乎都很好!