client.get_bucket() returns error: api_request() got an unexpected keyword argument 'extra_api_info'

client.get_bucket() returns error: api_request() got an unexpected keyword argument 'extra_api_info'

我正在尝试使用云函数将换行符分隔的 JSON 字符串存储在 GCS 存储桶中,但出现错误。我首先将数据框转换为 ndjson,然后尝试将其上传到我的 GCS 存储桶,如下所示。上面还有更多代码,但与我的问题无关:

import pandas as pd
from google.cloud import storage
from google.cloud.storage import blob

df = df.to_json(orient="records", lines=True)

storage_client = storage.Client(project='my-project')
bucket = storage_client.get_bucket('my-bucket')
blob = bucket.blob('my-blob')
blob.upload_from_string(df)

当运行这个时,我在日志中发现以下错误:

Exception on / [POST] Traceback (most recent call last): 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/app.py", line 2073, in wsgi_app response = self.full_dispatch_request() 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/app.py", line 1518, in full_dispatch_request rv = self.handle_user_exception(e) 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/app.py", line 1516, in full_dispatch_request rv = self.dispatch_request() 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/flask/app.py", line 1502, in dispatch_request return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args) 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/functions_framework/__init__.py", line 99, in view_func return function(request._get_current_object()) 
File "/workspace/main.py", line 66, in my_request bucket = storage_client.get_bucket('my-bucket') 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/storage/client.py", line 787, in get_bucket retry=retry, 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/storage/bucket.py", line 1037, in reload retry=retry, 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/storage/_helpers.py", line 244, in reload _target_object=self, 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/storage/client.py", line 373, in _get_resource _target_object=_target_object, 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/cloud/storage/_http.py", line 73, in api_request return call() 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/retry.py", line 288, in retry_wrapped_func on_error=on_error, 
File "/layers/google.python.pip/pip/lib/python3.7/site-packages/google/api_core/retry.py", line 190, in retry_target return target() TypeError: api_request() got an unexpected keyword argument 'extra_api_info'

这个 'extra_api_info' 参数似乎是罪魁祸首,但我不知道这意味着什么,并且在遵循完全相同的方法时从未遇到过这个错误,所以我想知道这是否归因于某些'google.cloud' Python 模块的不同版本之间的变化。

我找到了我自己问题的答案。确实是我怀疑的模块版本问题

在我的 requirements.txt 文件中指定 google.cloud.storage==1.44.0 解决了这个问题,因为我的代码似乎与该模块的最新版本不兼容(出于让我逃避的原因)。