dopy.manager.DoError: Unable to authenticate you

2024/10/13 17:18:46

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 osfrom dopy.manager import DoManagerimport urllib3.contrib.pyopensslurllib3.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.

Answer

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://en.xdnf.cn/q/118055.html

Related Q&A

subprocess.Popen: OSError: [Errno 2] No such file or directory only on Linux

This is not a duplicate of subprocess.Popen: OSError: [Errno 13] Permission denied only on Linux as that problem occurred due to wrong permissions. That has been fixed and this is an entirely different…

Windows Theano Keras - lazylinker_ext\mod.cpp: No such file or directory

I am installing Theano and Keras follwing the How do I install Keras and Theano in Anaconda Python on Windows?, which worked fine for me with an older release before. Now I have upgraded to the latest…

Python Threading: Making the thread function return from an external signal

Could anyone please point out whats wrong with this code. I am trying to return the thread through a variable flag, which I want to control in my main thread. test27.pyimport threading import timelock …

Python join data lines together

Hello i have dataset a few thousand lines which is split in even and odd number lines and i cant find a way to join them together again in the same line. Reading the file and overwriting it is fine or …

How to undraw plot with Zelle graphics?

This is a code problem for Python 3.5.2 using John Zelles graphics.py:I have spent a good amount of time looking for the answer here, but just can not figure it out. The function undraw() exists just l…

/bin/sh: line 62: to: command not found

I have a python code in which I am calling a shell command. The part of the code where I did the shell command is:try:def parse(text_list):text = \n.join(text_list)cwd = os.getcwd()os.chdir("/var/…

Using PyMySQL with MariaDB

I have read this article about switching from MySQL to MariaDB on Ubuntu. The article claims that it would be not problem to switch between the two. Currently, I am using PyMySQL to connect to my MySQL…

Overloading str in Python

I have code that looks like the following:class C(str):def __init__(self, a, b):print(init was called!)super().__init__(b)self.a = ac = C(12, c)When I try to run it, it gives me the following error:Tra…

Why cant I install Pillow on my mac? It gives some errors

here is the error from installing Pillow. Im using OS X Mavericks. I tried installing Pillow through pip install.._imaging.c:391:28: warning: implicit conversion loses integer precision: long to int [-…

what on earth the unicode number is?

in python:>>> "\xc4\xe3".decode("gbk").encode("utf-8") \xe4\xbd\xa0 >>> "\xc4\xe3".decode("gbk") u\u4f60we can get two conclusions:1.…