【问题标题】:*** google.api_core.exceptions.PermissionDenied: 403 Error opening file: gs://test_documents/uploads/2c4cd57cea679abd7dde9b20023a6c2c.pdf*** google.api_core.exceptions.PermissionDenied:403 打开文件时出错:gs://test_documents/uploads/2c4cd57cea679abd7dde9b20023a6c2c.pdf
【发布时间】:2019-10-03 19:22:32
【问题描述】:

我已经多次看到类似的问题,其中包含一些解决问题的建议步骤,我相信我已经遵循了这些步骤。代码非常直接来自示例,除了我在一个程序中做所有事情......将文件加载到 GCS 然后尝试使用 Vision 处理文件。我在顶部设置了一个环境变量,我认为它应该适用于这两个函数...文件已成功上传到 GCS 浏览器并确认 URI。权限被拒绝错误令人费解,因为凭据具有所有者权限...

想法?一旦调用了client.async_batch_annotate_files..,这个东西就死了

-> 操作 = client.async_batch_annotate_files(requests=[async_request]) (pdb) google.api_core.exceptions.PermissionDenied:403 打开文件时出错:gs://test_documents/uploads/2c4cd57cea679abd7dde9b20023a6c2c.pdf。

from google.cloud import vision
from google.cloud import storage
from google.protobuf import json_format
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]=config.gstorage
mime_type = 'application/pdf'
batch_size = 2

doc = DocumentMaster.objects.get(document_id=14)
bname = 'test_documents'
fname = doc.document_hash_key+".pdf"
in_target = os.path.join("uploads",fname)
out_target = os.path.join("document_json",fname)

fullpath = os.path.join(bname,in_target)
fullpath2 = os.path.join(bname,out_target)
private_in = "gs://"+fullpath
private_out = "gs://test_documents/document_json"

CloudStorage = storage.Client()
StorageBucket = CloudStorage.get_bucket(bname)
blob = StorageBucket.blob(in_target)
blob.upload_from_filename(doc.document_original.path)

client = vision.ImageAnnotatorClient()

feature = vision.types.Feature(type=vision.enums.Feature.Type.DOCUMENT_TEXT_DETECTION)

gcs_source = vision.types.GcsSource(uri=private_in)
input_config = vision.types.InputConfig(gcs_source=gcs_source, mime_type=mime_type)
gcs_destination = vision.types.GcsDestination(uri=private_out)
output_config = vision.types.OutputConfig(gcs_destination=gcs_destination, batch_size=batch_size)

async_request = vision.types.AsyncAnnotateFileRequest(features=[feature], input_config=input_config,output_config=output_config)

operation = client.async_batch_annotate_files(requests=[async_request])
print('Waiting for the operation to finish.')
operation.result(timeout=30)

【问题讨论】:

    标签: python google-cloud-storage google-cloud-vision


    【解决方案1】:

    事实证明,我低估了 GCS 云存储中特定管理员的作用。虽然项目有服务帐户,但它还需要获得明确许可才能检索它刚刚上传的文件...关闭

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      • 2019-08-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多