dopy.manager.DoError:无法对您进行身份验证 [英] dopy.manager.DoError: Unable to authenticate you
问题描述
我正在尝试配置一个虚拟机(具有Vagrant和Ansible),需要使用file.py来完全正确配置该计算机(根据我正在研究的书),我正在使用DigitalOcean API V2,但是由于我没有有效的信用卡,我的账户被冻结了,所以我不得不将DigitalOcean更改为AWS,因为我工作的公司在AWS上拥有一个账户,现在我使用客户ID"和"api键",因此返回了上述问题...当我尝试使用"python file.py"命令时,输出再次显示:
I'm trying to configure a Virtual Machine(with Vagrant and Ansible), that needs a file.py to the full correct configuration of this machine (according to the book that I'm studying),I'm was using the DigitalOcean API V2, but as I have no a valid credit card my account is bloked,so I had to change DigitalOcean to AWS,as the company where I work have an account with AWS,now I take the 'client id' and 'api key' from AWS VM,so the foregoing problems returned...when I try use the "python file.py" command the output says again:
dopy.manager.DoError:无法对您进行身份验证.
dopy.manager.DoError: Unable to authenticate you.
**the file.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_KEY")
#do = DoManager(cliend_id, api_key)
do = DoManager(None, api_token, api_version=2)
keys = do.all_ssh_keys()
print "ssh key name\tid"
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"])
感谢您的帮助.
推荐答案
尝试删除api_token中的引号:
Try to remove quotes from api_token:
do = DoManager(None, api_token, api_version=2)
否则,您的令牌始终是文字字符串 api_token ,而不是变量api_token.
Otherwise your token is always literal string api_token, not a variable api_token.
这篇关于dopy.manager.DoError:无法对您进行身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!