Skip to content

PermissionDenied: 403 Error opening file: gs://myocrbucket-v/2.pdf. #1471

@vtangutoori

Description

@vtangutoori

Hi,
I am trying to prepare some NLP test data by performing OCR on a bunch of pdf documents using google cloud vision OCR and to test it out on a single file i have created a bucket in google cloud, uploaded a pdf file to it and tried to OCR that file using the below code, however i am getting the permissiondenied error, i tried my best to find documentation on how to properly provide permissions and followed the instructions on google documentation by activating the service account as a bearer. Can anyone please look at my code and tell me if i am missing something here.

##I activated the service key using following command line argument.
gcloud auth activate-service-account --key-file C:\Python27\GoogleOCR\key.json

import argparse
import re
import os
from google.cloud import storage
from google.cloud import vision_v1p2beta1 as vision
from google.protobuf import json_format

##i have taken sections of code from google documentation on PDF, TIFF file formats.
mime_type = 'application/pdf'
batch_size = 2
client = vision.ImageAnnotatorClient()

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

gcs_source = vision.types.GcsSource(uri='gs://myocrbucket-v/2.pdf')(uri="gs://{}/{}".format('Buckets/myocrbucket-v','2.pdf'))

input_config = vision.types.InputConfig(gcs_source=gcs_source, mime_type=mime_type)

gcs_destination = vision.types.GcsDestination(uri='gs://myocrbucket-v/2.pdf')(uri="gs://{}/{}".format('Buckets/myocrbucket-v','2.pdf'))
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(operation.result)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions