Skip to content Skip to sidebar Skip to footer

How Can I Avoid Http Error Code 429 From Google Vision Api?

I've been using Google Vision API to perform OCR tasks in some documents using Python. It begins working perfectly, until I start receiving Http Error Code 429, which means I am do

Solution 1:

You have used, application default credentials,

credentials = GoogleCredentials.get_application_default()

Maybe it is not able to find the credentials and use for request and so making anonymous request to API, that is not allowing more than 2 or 3 requests as in your case, I was also facing the same issue and found the work around as:

(Note: If you haven't set up an API key or service account key, please refer this doc to create one.)

for development: using API key

you could use it like:

self.vision = discovery.build(
    'vision', 'v1', credentials=credentials,
    discoveryServiceUrl=DISCOVERY_URL, developerKey='your_api_key'

)

for production: using service account key

from oauth2client.service_account importServiceAccountCredentialsscopes= ['https://www.googleapis.com/auth/sqlservice.admin']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
    '/path/to/keyfile.json', scopes=scopes)

you can find a list of scopes to use here.

Also, you need to set this environment variable:

GOOGLE_APPLICATION_CREDENTIALS="/path/to/secret-key-file"

You need not increase the sleep time with every request, just increase it if a request fails while using any of the above-mentioned approaches. look for the exponential backoff algorithm in docs.

Post a Comment for "How Can I Avoid Http Error Code 429 From Google Vision Api?"