[英]Google storage.Client throwing .__int__ error: takes 2 positional arguments but 3 were given
When trying to authenticate my local Google credentials to access Google Cloud Storage I'm given the error:尝试验证我的本地 Google 凭据以访问 Google Cloud Storage 时出现错误:
TypeError: init () takes 2 positional arguments but 3 were given
TypeError: init () 接受 2 个位置参数,但给出了 3 个
This happens if I run:如果我运行,就会发生这种情况:
from google.cloud import storage
client=storage.Client()
I've tried adding我试过添加
credentials, project = google.auth.default(
scopes=[
"https://www.googleapis.com/auth/drive",
"https://www.googleapis.com/auth/cloud-platform",
'https://www.googleapis.com/auth/devstorage.full_control',
'https://www.googleapis.com/auth/devstorage.read_only',
'https://www.googleapis.com/auth/devstorage.read_write'
]
)
and和
storage_client = storage.Client.__init__(self, credentials=credentials, project=project, client_info=None)
but have not been able to resolve the error.但未能解决错误。 Any help appreciated!
任何帮助表示赞赏! Let me know if I can provide more context.
让我知道是否可以提供更多上下文。
The libraries I have installed are:我安装的库是:
Try not to call __init__
directly when instantiating the storage client.实例化存储客户端时尽量不要直接调用
__init__
。 Also, note that you put self
as a parameter, which is why you are sending one additional positional argument.另外,请注意您将
self
作为参数,这就是为什么您要发送一个额外的位置参数。
Let's try removing those additional args:让我们尝试删除那些额外的参数:
storage_client = storage.Client(credentials=credentials, project=project)
Thanks for the help!谢谢您的帮助! I was able to resolve this issue with this code:
我能够用这段代码解决这个问题:
credentials, project = google.auth.default()
client = storage.Client(project=project)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.