可读VM:TypeError: __init__()接受至少3个参数(给定2个)

时间:2021-02-25 23:18:13

I'm learning about virtual machine and others, I'm trying to configure a VM(with Ansible and DigitalOcean API V2)that needs a file.py to the full correct configuration of this machine (according to the book that I'm studying), but when I try use the command python do_api_v1.py the output says:

我正在学习虚拟机和其他东西,我正在尝试配置一个需要文件的VM(具有Ansible和DigitalOcean API V2)。py到这台机器的完全正确配置(根据我正在学习的书),但是当我尝试使用python do_api_v1命令时。py输出说:

**Traceback (most recent call last):

**回溯(最近一次电话):

File "do_api_v1.py", line 12, in do = DoManager(token) TypeError: init() takes at least 3 arguments (2 given) **

do_api_v1文件”。py",第12行,在do = DoManager(令牌)类型错误中:init()至少接受3个参数(2给定)**

the file do_api_v1.py it is like:

文件do_api_v1。py就像:

"""
dependencias: 
    sudo pip install dopy pyopenssl ndg-httpsclient pyasn1
"""

import os
from dopy.manager import DoManager
import urllib3.contrib.pyopenssl
urllib3.contrib.pyopenssl.inject_into_urllib3()


api_version = os.getenv("DO_API_VERSION")
api_token=os.getenv("DO_API_

do = DoManager(None, 'api_token', 'api_version')

keys = do.all_ssh_keys()
print "ssh key nametid"
for key in keys:
    print "%s\t%d" % (key["name"], key["id"])

print "Image name\tid"
imgs = do.all_images()
for img in imgs:
    if img["slug"] == "ubuntu-14-04-x64":
        print "%s\t%d" % (img["name"], img["id"])

print "Region name\tid"
regions = do.all_regions()
for region in regions:
    if region["slug"] == "nyc2":
        print "%s\t%d" % (region["slug"], region["id"])

print "Size name\tid"
sizes = do.sizes()
for size in sizes:
    if size["slug"] == "512mb":
        print "%s\t%d" % (size["slug"], size["id"])

2 个解决方案

#1


0  

You are not passing enough arguments to DoManager as the error message says. You need to pass an obligatory client_id as the first argument, and an api_key as the second.

正如错误消息所说,您没有向DoManager传递足够的参数。您需要传递一个强制性的client_id作为第一个参数,第二个参数是api_key。

#2


0  

DoManager requires more arguments.

DoManager需要更多的参数。

From the docs:

从文档:

For V1 of the API:

对于API的V1:

# export DO_CLIENT_ID='client_id'
# export DO_API_KEY='long_api_key'
>>> from dopy.manager import DoManager
>>> do = DoManager('client_id', 'long_api_key')

And for V2:

和V2:

# export DO_API_VERSION='2'
# export DO_API_TOKEN='api_token'
>>> from dopy.manager import DoManager
>>> do = DoManager(None, 'api_token', api_version=2)

Both versions require you to supply an API key, but V2 doesn't need the client ID anymore.

两个版本都需要您提供API密钥,但是V2不再需要客户机ID。

#1


0  

You are not passing enough arguments to DoManager as the error message says. You need to pass an obligatory client_id as the first argument, and an api_key as the second.

正如错误消息所说,您没有向DoManager传递足够的参数。您需要传递一个强制性的client_id作为第一个参数,第二个参数是api_key。

#2


0  

DoManager requires more arguments.

DoManager需要更多的参数。

From the docs:

从文档:

For V1 of the API:

对于API的V1:

# export DO_CLIENT_ID='client_id'
# export DO_API_KEY='long_api_key'
>>> from dopy.manager import DoManager
>>> do = DoManager('client_id', 'long_api_key')

And for V2:

和V2:

# export DO_API_VERSION='2'
# export DO_API_TOKEN='api_token'
>>> from dopy.manager import DoManager
>>> do = DoManager(None, 'api_token', api_version=2)

Both versions require you to supply an API key, but V2 doesn't need the client ID anymore.

两个版本都需要您提供API密钥,但是V2不再需要客户机ID。