dopy.manager.DoError: Unable to authenticate you

喜你入骨 提交于 2019-12-25 07:59:52

问题


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: 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"])

I appreciate any help.


回答1:


Try to remove quotes from api_token:

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

Otherwise your token is always literal string api_token, not a variable api_token.



来源:https://stackoverflow.com/questions/39852205/dopy-manager-doerror-unable-to-authenticate-you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!