【发布时间】:2020-10-04 08:11:07
【问题描述】:
我有一个调用 API 的 Google Cloud 函数。此调用需要我已上传到存储桶的 .pem 和 .key 安全证书。我正在尝试在云功能中使用它们。这似乎是一项简单的任务,但我尝试过或在线找到的代码都没有。这是我目前拥有的:
def receive_request(request):
request_json = request.get_json()
if request_json:
source_bucket = storage.get_bucket('bucket_name')
pem_file = source_bucket.get_blob(request_json.get('pem'))
key_file = source_bucket.get_blob(request_json.get('key'))
url = 'https://api_url/api/v2/acls'
response = requests.get(url, cert=(pem_file,key_file ))
JSON 就在哪里:
{"pem":"file_name.pem","key":"file_name.key"}
我得到的错误信息是:
Error: function terminated. Recommended action: inspect logs for termination reason. Details:
stat: path should be string, bytes, os.PathLike or integer, not Blob
当我尝试使用 GS 路径(“gs://bucket_name/file_name.key”)时,GCP 没有部署该功能。如何正确构建这两个文件的导入?
【问题讨论】:
-
您将对象
google.cloud.storage.blob.Blob传递给requests.get。您需要读取 blob 并传递该数据。看pem_file_data = pem_file.download_as_string()
标签: google-cloud-platform google-cloud-functions google-cloud-storage