python-3.x - GCP 功能部署功能失败
问题描述
在 GCP 函数中创建了一个 python 函数来修改存储中对象的元数据。部署时显示错误,错误信息如下:
Function failed on loading user code. This is likely due to a bug in the user code.
Error message: Error: please examine your function logs to see the error cause:
https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional
troubleshooting documentation can be found at
https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit
https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting
documentation.
我的功能代码如下:
from google.cloud import storage
def set_blob_metadata(bucket_name, blob_name):
"""Set a blob's metadata."""
# bucket_name = 'your-bucket-name'
# blob_name = 'your-object-name'
storage_client = storage.Client()
bucket = storage_client.bucket(lrving)
blob = bucket.get_blob(index.html)
metadata = {'Cache-Control': 'no-store'}
blob.metadata = metadata
blob.patch()
print("The metadata for the blob {} is {}".format(blob.name, blob.metadata))
如何解决这个问题呢?谢谢!</p>
解决方案
根据您提到的错误消息,问题是由于您的运行时没有云存储模块引起的。除了 Guillaume 的回答之外,您还需要在函数部署期间安装该依赖项。您可以通过将 google-cloud-storage 添加到您的 requirements.txt 文件来实现。
例如:
google-cloud-storage==1.41.0
可以在此处找到 有关如何为 Cloud Functions 指定 Python 依赖项的更多信息。
推荐阅读
- python - 网页抓取文章得到 AttributeError: 'str' object has no attribute 'text'
- arrays - 使用堆栈查找数组中的下一个更大元素背后的真正直觉是什么
- jupyter-notebook - Colab pro 卡在忙碌状态,并在底部的 [时间] 显示已完成
- sql - MS SQL Server - 包含多个连接的查询显示正确数量的条目,结合 OR 条件,我得到很多重复项
- python - 创建一个新列,将一个列和一个长度不等的数组相乘
- python - 如何拆分重复所有相同模式行n次的文本并在python中创建n个不同的文本文件?
- webdriver-io - 无法使用 Appium、Javascript 和 webdriverio 为元素调用 setValue
- c++ - 有效地找到康托尔有理数集的第 N 项
- c++ - 如何在循环线程中使用 wait_for?
- javascript - 我的自定义 Netlify 无服务器函数不会从 Prismic API 获取数据