简体   繁体   English

Google storage.Client 抛出 .__int__ 错误:接受 2 个位置参数,但给出了 3 个

[英]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:我安装的库是:

  • google-api-core 2.8.1 pypi_0 pypi谷歌 api 核心 2.8.1 pypi_0 pypi
  • google-api-python-client 1.12.11 pypi_0 pypi google-api-python-client 1.12.11 pypi_0 pypi
  • google-auth 1.35.0 pyh6c4a22f_0 conda-forge谷歌身份验证 1.35.0 pyh6c4a22f_0 conda-forge
  • google-auth-httplib2 0.1.0 pyhd8ed1ab_1 conda-forge google-auth-httplib2 0.1.0 pyhd8ed1ab_1 conda-forge
  • google-auth-oauthlib 0.5.1 pypi_0 pypi google-auth-oauthlib 0.5.1 pypi_0 pypi
  • google-cloud 0.34.0 pypi_0 pypi谷歌云 0.34.0 pypi_0 pypi
  • google-cloud-bigquery 3.1.0 pypi_0 pypi谷歌云大查询 3.1.0 pypi_0 pypi
  • google-cloud-bigquery-storage 2.13.1 pypi_0 pypi谷歌云大查询存储 2.13.1 pypi_0 pypi
  • google-cloud-core 2.3.0 pypi_0 pypi谷歌云核心 2.3.0 pypi_0 pypi
  • google-cloud-sdk 387.0.0 py39h6e9494a_0谷歌云 SDK 387.0.0 py39h6e9494a_0
    conda-forge康达锻造
  • google-cloud-storage 2.3.0 pypi_0 pypi谷歌云存储 2.3.0 pypi_0 pypi
  • google-crc32c 1.1.2 py39h9ed2024_0谷歌-crc32c 1.1.2 py39h9ed2024_0
  • google-resumable-media 2.3.3 pyhd8ed1ab_0谷歌可恢复媒体 2.3.3 pyhd8ed1ab_0
    conda-forge康达锻造
  • googleapis-common-protos 1.56.2 py39h6e9494a_0 googleapis-common-protos 1.56.2 py39h6e9494a_0
    conda-forge康达锻造

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.

相关问题 错误:choice()接受2个位置参数,但给出了4个 - error: choice() takes 2 positional arguments but 4 were given argparse错误“接受0个位置参数,但给出了2个” - argparse error “takes 0 positional arguments but 2 were given” 需要 2 个位置 arguments 但给出了 3 个 - Takes 2 positional arguments but 3 were given 类型错误:fit() 需要 2 个位置参数,但给出了 3 个 - Type error: fit() takes 2 positional arguments but 3 were given Pygame 错误:loot() 需要 2 个位置参数,但给出了 3 个 - Pygame Error: loot() takes 2 positional arguments but 3 were given 编辑获取错误 main() 需要 2 个位置参数,但给出了 3 个 - EDITGetting error main() takes 2 positional arguments but 3 were given 类型错误 /login authenticate() 从 0 到 1 位置 arguments 但给出了 2 - Type Error /login authenticate() takes from 0 to 1 positional arguments but 2 were given 意外错误:replace() 需要 2 个位置 arguments 但给出了 3 个 - Unexpected error: replace() takes 2 positional arguments but 3 were given 在 sklearn 中创建自定义变压器时出错 - 需要 2 个位置 arguments 但给出了 3 个 - Error creating a custom transformer in sklearn - takes 2 positional arguments but 3 were given open()接受1到3个位置参数,但给出了5个 - open() takes from 1 to 3 positional arguments but 5 were given
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM