App Engine默认凭据在本地开发服务器上停止工作

时间:2017-08-16 18:25:08

标签: python google-app-engine oauth google-cloud-vision

我正在使用Google vision API在本地运行应用引擎。我正在使用OAuth的应用程序默认凭据并构建API客户端来执行标签检测。每当我创建对象时,它都会刷新凭证

DISCOVERY_URL = 'https://{api}.googleapis.com/$discovery/rest?version={apiVersion}'

class VisionApi(object):
    def __init__(self):
        self.vision = self._create_client()

    def _create_client(self):
        credentials = GoogleCredentials.get_application_default()
        return discovery.build(
            'vision', 'v1', credentials=credentials,
            discoveryServiceUrl=DISCOVERY_URL)

这昨天工作得很好,我没有改变它。当我今天尝试使用它时,它会尝试两次获取凭据,然后我收到以下401错误:

INFO     2017-08-16 18:12:14,228 discovery.py:863] URL being requested: POST https://vision.googleapis.com/v1/images:annotate?alt=json
INFO     2017-08-16 18:12:14,228 transport.py:157] Attempting refresh to obtain initial access_token
WARNING  2017-08-16 18:12:14,237 urlfetch_stub.py:504] Stripped prohibited headers from URLFetch request: ['content-length']
INFO     2017-08-16 18:12:14,542 transport.py:185] Refreshing due to a 401 (attempt 1/2)
WARNING  2017-08-16 18:12:14,544 urlfetch_stub.py:504] Stripped prohibited headers from URLFetch request: ['content-length']
INFO     2017-08-16 18:12:14,823 transport.py:185] Refreshing due to a 401 (attempt 2/2)
WARNING  2017-08-16 18:12:14,826 urlfetch_stub.py:504] Stripped prohibited headers from URLFetch request: ['content-length']

HttpError: <HttpError 401 when requesting https://vision.googleapis.com/v1/images:annotate?alt=json returned "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.">

为什么昨天有效,但今天不工作?我知道我可以使用服务器到服务器凭据的路线,但它没有这个工作,我宁愿继续使用API​​。

0 个答案:

没有答案