【问题标题】:"We can not access the URL currently."“我们目前无法访问该 URL。”
【发布时间】:2017-12-20 12:51:42
【问题描述】:

当返回“我们目前无法访问该 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."
      }
    }
  ]
}

【问题讨论】:

  • 您有解决此问题的方法吗?现在是 2019 年,但它仍然不起作用。抛出同样的错误。

标签: google-cloud-platform google-cloud-vision


【解决方案1】:

截至 2017 年 8 月,这是 Google Cloud Vision API (source) 的一个已知问题。它似乎对某些用户来说是重现的,但不是确定性的,而且我自己也遇到过很多图像。

当前的解决方法包括将您的内容上传到 Google Cloud Storage 并传递其 gs:// uri(注意它不必在 GCS 上公开可读)或在本地下载图像并以 base64 格式将其传递给视觉 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 }
  ]
})

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      当我尝试使用 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));
      

      【讨论】:

        【解决方案4】:

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

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

        【讨论】:

          【解决方案5】:

          就我而言,我尝试检索 Cloudinary 我们的主要图像托管提供商使用的图像。

          当我访问相同的图像但托管在我们的辅助 Rackspace 驱动的 CDN 上时,Google OCR 能够访问该图像。

          当我能够通过网络浏览器访问图像时,不知道为什么 Cloudinary 不起作用,但只是我的小解决方法。

          【讨论】:

            【解决方案6】:

            对我来说,我通过请求 URI(例如:gs://bucketname/filename.jpg)而不是公共 URL 或经过身份验证的 URL 解决了这个问题。

               const vision = require('@google-cloud/vision'); 
               function uploadToGoogleCloudlist (req, res, next) {
                   const originalfilename = req.file.originalname;
                   const bucketname = "yourbucketname";
                   const imageURI = "gs://"+bucketname+"/"+originalfilename;
                   
                   const client = new vision.ImageAnnotatorClient(
                        {
                        projectId: 'yourprojectid',
                        keyFilename: './router/fb/yourprojectid-firebase.json'
                        }
                    );
            
                var visionjson;
            
                async function getimageannotation() {
                    const [result] = await client.imageProperties(imageURI);
                    visionjson = result;
                    console.log ("vision result: "+JSON.stringify(visionjson));
                    return visionjson;
                    }
            
                getimageannotation().then( function (result){
                    var datatoup =  {
                                url: imageURI || ' ',
                                filename: originalfilename   || ' ',
                                available: true,
                                vision: result,
                                            };
                
                })
                .catch(err => {
                    console.error('ERROR CODE:', err);
                    });
            
                next();
            
                }
            

            【讨论】:

              【解决方案7】:

              几天前我遇到了同样的问题。

              在我的情况下,问题是由于使用队列并从同一 IP 一次调用 api 请求而发生的。将并行进程数从 8 个更改为 1 个后,此类错误的数量从约 30% 减少到不到 1%。

              也许它会帮助某人。我认为 google 方面在加载远程图像方面存在一些内部限制(因为正如人们所报告的那样,使用 google 存储也可以解决问题)。

              【讨论】:

                【解决方案8】:

                同样的请求也适用于我。图像主机可能暂时关闭和/或他们身边有问题。如果您重试该请求,它将主要为您工作。

                【讨论】:

                  猜你喜欢
                  • 2021-03-12
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 1970-01-01
                  • 2021-08-29
                  相关资源
                  最近更新 更多