简体   繁体   中英

libcloud: missing 1 required positional argument error during driver init

I'm using:

  • libcloud 2.2.1
  • python 3.5.2
  • virtualenv
  • GCE service account with a json credential file

Python code looks like this:

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.

  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. 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).
  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. That is what led to the actual error I was seeing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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