在部署云功能时,我收到了下面提到的错误
我正在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
我测试了您的代码,当它被包装在正确的HTTP函数格式中时,它可以完美地工作
#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