Google Cloud Vision API文本检测google.gax.errors.RetryError:GaxError

时间:2017-05-21 05:59:42

标签: python google-cloud-vision

我是Google API的新手。 最近,我使用Google Vision API但遇到了以下问题:

google.gax.errors.RetryError: GaxError(Exception occurred in retry method that was not classified as transient, caused by <_Rendezvous of RPC that terminated with (StatusCode.RESOURCE_EXHAUSTED, Insufficient tokens for quota 'DefaultGroup' and limit 'USER-100s' of service 'vision.googleapis.com' for consumer 'project_number:XXX'.)>)

我尝试了解决方案&#34;创建服务accout&#34;生成服务json密钥并在py.script中调用它, 它将在几乎3~4 url​​中首先工作,但在下一个url中会出错。 这是我的检测代码:

import argparse
import io
from google.cloud import vision
vision_client = vision.Client.from_service_account_json('/Users/bruce0621/Downloads/esun-bank-adc1897dba67.json')
...
def detect_text_uri(uri):
    """Detects text in the file located in Google Cloud Storage or on the Web.
    """
    vision_client = vision.Client()
    image = vision_client.image(source_uri=uri)

    texts = image.detect_text()
    print('Texts:')

    for text in texts:
        print('\n"{}"'.format(text.description))

        vertices = (['({},{})'.format(bound.x_coordinate, bound.y_coordinate)
                    for bound in text.bounds.vertices])

        print('bounds: {}'.format(','.join(vertices)))

我调用&#34; detect.py&#34;在另一个py.script:

detect.detect_text_uri('...')

1 个答案:

答案 0 :(得分:0)

呼叫:

export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials.json

gcloud auth application-default login

这会将您的环境配置为使用您下载的服务帐户凭据。