如何解决部署时云功能抛出错误
部署云功能时出现以下错误
我在Requirements.txt中使用最新版本的云存储 另外,我正在使用存储客户端的list_blob功能,从那时起,我在部署该功能时面临以下错误
ERROR: (gcloud.functions.deploy) OperationError: code=3,message=Function failed on loading user code.
Error message: __init__() takes 2 positional arguments but 3 were given
Detailed stack trace:
from datetime import datetime
Traceback (most recent call last):
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v1.py",line 315,in check_
or_load_user_function
_function_handler.load_user_function()
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v1.py",line 190,in load_u
ser_function
spec.loader.exec_module(main_module)
File "<frozen importlib._bootstrap_external>",line 728,in exec_module
File "<frozen importlib._bootstrap>",line 219,in _call_with_frames_removed
File "/user_code/main.py",line 52,in <module>
CS = storage.Client()
File "/env/local/lib/python3.7/site-packages/google/cloud/storage/client.py",line 129,in __init__
self._connection = Connection(self,**kw_args)
File "/env/local/lib/python3.7/site-packages/google/cloud/storage/_http.py",line 35,in __init__
super(Connection,self).__init__(client,client_info)
TypeError: __init__() takes 2 positional arguments but 3 were given
解决方法
我测试了您的代码,将其包装在correct HTTP function format
中后,它可以完美地工作#Your function
def list_blobs(bucket_name):
from google.cloud import storage
storage_client = storage.Client()
blobs = storage_client.list_blobs(bucket_name)
fileList = []
for blob in blobs:
fileList.append(blob.name)
return fileList
#function wrapper
def test_list_blob(request):
ret = list_blobs('temp-veolia-export')
return str(ret),200
并部署
gcloud functions deploy --trigger-http --entry-point=test_list_blob --runtime=python37 \
--region=us-central1 --allow-unauthenticated python-test-storage
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。