我试着运行一个简单的脚本
https://github.com/GoogleCloudPlatform/training-data-analyst/blob/master/courses/data_analysis/lab2/python/grepc.py
(此代码是连接到Google存储的数据流管道)
上周起作用了。但当我现在运行它时,总是会出现同样的错误:

> Traceback (most recent call last):
  File "grepc.py", line 50, in <module>
    run()
  File "grepc.py", line 44, in run
    | 'write' >> beam.io.WriteToText(output_prefix)
  File "/usr/local/lib/python2.7/dist-packages/apache_beam/io/textio.py", line 391, in __init__
    skip_header_lines=skip_header_lines)
  File "/usr/local/lib/python2.7/dist-packages/apache_beam/io/textio.py", line 89, in __init__
    validate=validate)
  File "/usr/local/lib/python2.7/dist-packages/apache_beam/io/filebasedsource.py", line 105, in __init__
    self._validate()
  File "/usr/local/lib/python2.7/dist-packages/apache_beam/options/value_provider.py", line 109, in _f
    return fnc(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/apache_beam/io/filebasedsource.py", line 165, in _validate
    match_result = FileSystems.match([pattern], limits=[1])[0]
  File "/usr/local/lib/python2.7/dist-packages/apache_beam/io/filesystems.py", line 131, in match
    return filesystem.match(patterns, limits)
  File "/usr/local/lib/python2.7/dist-packages/apache_beam/io/gcp/gcsfilesystem.py", line 138, in match
    raise BeamIOError("Match operation failed", exceptions)
apache_beam.io.filesystem.BeamIOError: Match operation failed with exceptions {'gs://{MY_BUCKET}/javahelp/*.java': HttpAccessTokenRefreshError(u' This can occur if a VM was created with no service account or scopes.',)}

我不知道怎么解决这个问题。很多谷歌搜索也没用。

最佳答案

获取用于应用程序默认凭据的新用户凭据解决了我的问题。
这是我用过的
gcloud auth应用程序默认登录
这里有很好的记录https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login
您可以在这里找到解释:当您开发的代码通常使用服务帐户,但需要在更容易提供用户凭据的本地开发环境中运行代码时,此命令非常有用。凭据将应用于使用应用程序默认凭据客户端库的所有API调用
我找到的另一个解决方案是:下载计算引擎服务帐户的keyfile并导出GOOGLE_APPLICATION_凭据以指向keyfile

关于python - Google Cloud Shell HttpAccessTokenRefreshError:如果创建的VM没有服务帐户或范围,则可能发生这种情况,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44430393/

10-09 08:27