我正在创建一个googlecloud函数来启动一个computevm实例。我指的是关于这个主题的文档和一些答案,比如Using gcloud cli within a cloud function和https://stackoverflow.com/a/61343478/6352160
以下是云函数:
import base64
from googleapiclient import discovery
from google.auth import compute_engine
def hello_pubsub(event, context):
"""Triggered from a message on a Cloud Pub/Sub topic.
Args:
event (dict): Event payload.
context (google.cloud.functions.Context): Metadata for the event.
"""
pubsub_message = base64.b64decode(event['data']).decode('utf-8')
print(pubsub_message)
#credentials = GoogleCredentials.get_application_default()
credentials = compute_engine.Credentials()
service = discovery.build('compute', 'v1',credentials=credentials)
# Project ID for this request.
project = 'Project name'
# The name of the zone for this request.
zone = 'zone'
# Name of the instance resource to start.
instance = 'instance-name'
try:
request = service.instances().start(project=project, zone=zone, instance=instance)
response = request.execute()
except Exception as e:
print(e)
print('VM Instance started')
“要求”选项卡是:
google-api-python-client
当我运行这个函数时,我得到以下错误
E 2020-07-02T01:06:10.808Z TestCloudFunction lt7vm36u2i1w file_cache is unavailable when using oauth2client >= 4.0.0 or google-auth TestCloudFunction lt7vm36u2i1w
E 2020-07-02T01:06:10.808Z TestCloudFunction lt7vm36u2i1w Traceback (most recent call last): TestCloudFunction lt7vm36u2i1w
E 2020-07-02T01:06:10.808Z TestCloudFunction lt7vm36u2i1w File "/env/local/lib/python3.7/site-packages/googleapiclient/discovery_cache/file_cache.py", line 33, in <module> TestCloudFunction lt7vm36u2i1w
E 2020-07-02T01:06:10.808Z TestCloudFunction lt7vm36u2i1w from oauth2client.contrib.locked_file import LockedFile TestCloudFunction lt7vm36u2i1w
E 2020-07-02T01:06:10.808Z TestCloudFunction lt7vm36u2i1w ModuleNotFoundError: No module named 'oauth2client.contrib.locked_file' TestCloudFunction lt7vm36u2i1w
E 2020-07-02T01:06:10.808Z TestCloudFunction lt7vm36u2i1w TestCloudFunction lt7vm36u2i1w
E 2020-07-02T01:06:10.808Z TestCloudFunction lt7vm36u2i1w During handling of the above exception, another exception occurred: TestCloudFunction lt7vm36u2i1w
初始化计算API时,它看起来像是身份验证错误。 有人能告诉我怎么解决这个问题吗
更新:我注意到,尽管出现了这个错误,代码仍然成功地启动了Compute VM实例。然而,我仍然想知道为什么会显示此错误,以及如何修复此错误
这可以在GoogleAPI Python客户端(github here)的代码中找到
这似乎是>=oauth2client的4.0.0版本只是为了知道该功能不可用
我希望这会有帮助
相关问题 更多 >
编程相关推荐