简体   繁体   English

libcloud:驱动程序初始化期间缺少1个必需的位置参数错误

[英]libcloud: missing 1 required positional argument error during driver init

I'm using: 我正在使用:

  • libcloud 2.2.1 libcloud 2.2.1
  • python 3.5.2 python 3.5.2
  • virtualenv 虚拟环境
  • GCE service account with a json credential file 具有JSON凭证文件的GCE服务帐户

Python code looks like this: Python代码如下所示:

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver


def run():
    """ Run this script
    """
    ComputeEngine = get_driver(Provider.GCE)
    driver = ComputeEngine(user_id='****@****.com',
                           credential_file='serviceaccount.json',
                           project='****')

run()

When I run my code, I'm getting: 当我运行代码时,我得到:

Traceback (most recent call last):
  File "./myscript.py", line 47, in <module>
    run()
  File "./myscript.py", line 21, in run
    project='ebs-it', secure=True)
  File "/***/virtualenv/lib/python3.5/site-packages/libcloud/compute/drivers/gce.py", line 1795, in __init__
    super(GCENodeDriver, self).__init__(user_id, key, **kwargs)
  File "/***/virtualenv/lib/python3.5/site-packages/libcloud/common/base.py", line 975, in __init__
    self.connection = self.connectionCls(*args, **conn_kwargs)
TypeError: __init__() missing 1 required positional argument: 'secure'

This looks perfectly textbook to me. 这对我来说似乎是完美的教科书 Any idea what could be going wrong? 任何想法可能出什么问题吗?

The issue was two fold: unfamiliarity with Google's service accounts, which led to an error in coding. 这个问题有两个方面:不熟悉Google的服务帐户,这导致编码错误。

  1. Each service account has an email/ID associated with it, which I only discovered after clicking on 'Manage service accounts' on the Credentials screen. 每个服务帐户都有一个与之关联的电子邮件/ ID,我只有在“凭据”屏幕上单击“管理服务帐户”后才发现。 I was mistakenly using my google account as the user_id, since I couldn't figure out what else to put in the field (even though that didn't make sense, but I couldn't see an alternative). 我错误地将自己的Google帐户用作user_id,因为我无法弄清楚该字段中还有什么(即使那没有意义,但我看不到其他选择)。
  2. After examining the libcloud code, I discovered the credential_file parameter, which seemed to fit better than the key parameter that should be used for the service account file. 在检查libcloud代码之后,我发现了credential_file参数,该参数似乎比应该用于服务帐户文件的key参数更好。 That is what led to the actual error I was seeing. 那就是导致我看到的实际错误的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM