“我们目前无法访问该网址。”

问题描述 投票:8回答:5

当我们返回“我们目前无法访问该URL”时,我会调用google api。但资源必须存在且可以访问。

https://vision.googleapis.com/v1/images:annotate

请求内容:

{
  "requests": [
    {
      "image": {
        "source": {
          "imageUri": "http://yun.jybdfx.com/static/img/homebg.jpg"
        }
      },
      "features": [
        {
          "type": "TEXT_DETECTION"
        }
      ],
      "imageContext": {
        "languageHints": [
          "zh"
        ]
      }
    }
  ]
}

回复内容:

{
  "responses": [
    {
      "error": {
        "code": 4,
        "message": "We can not access the URL currently. Please download the content and pass it in."
      }
    }
  ]
}
google-cloud-platform google-cloud-vision
5个回答
1
投票

截至2017年8月,这是Google Cloud Vision API(source)的一个已知问题。它似乎是对一些用户的重复,但没有确定性,我自己用许多图像遇到它。

目前的解决方法包括将您的内容上传到Google云端存储并传递其gs:// uri(注意它不必在GCS上公开阅读)或在本地下载图像并将其传递到base64格式的vision API。

这是后一种方法的Node.js中的一个例子:

const request = require('request-promise-native').defaults({
  encoding: 'base64'
})

const data = await request(image)

const response = await client.annotateImage({
  image: {
    content: data
  },
  features: [
    { type: vision.v1.types.Feature.Type.LABEL_DETECTION },
    { type: vision.v1.types.Feature.Type.CROP_HINTS }
  ]
})

0
投票

同样的要求对我有用。图像主机可能暂时停机和/或有问题。如果您重试请求,它将主要适合您。


0
投票

对我来说,只能将图像上传到谷歌云平台并将其传递给URI参数。


0
投票

当我尝试使用firebase存储下载URL调用api时,我遇到了同样的问题(尽管最初有效)

环顾四周后,我在NodeJs的api文档中找到了以下示例。

NodeJs example

// Imports the Google Cloud client libraries
const vision = require('@google-cloud/vision');

// Creates a client
const client = new vision.ImageAnnotatorClient();

/**
 * TODO(developer): Uncomment the following lines before running the sample.
 */
// const bucketName = 'Bucket where the file resides, e.g. my-bucket';
// const fileName = 'Path to file within bucket, e.g. path/to/image.png';

// Performs text detection on the gcs file
const [result] = await client.textDetection(`gs://${bucketName}/${fileName}`);
const detections = result.textAnnotations;
console.log('Text:');
detections.forEach(text => console.log(text));

0
投票

我认为该错误是由Cloud Vision API拒绝在robots.txt文件阻止GooglebotGooglebot-Image的域上下载图像引起的。

其他人提到的解决方法实际上是正确的解决方案:自己下载图像并将它们传递到image.content字段或上传到Google Cloud Storage并使用image.source.gcsImageUri字段。

© www.soinside.com 2019 - 2024. All rights reserved.