Функция Python:
Код: Выделить всё
def authenticate(base_endpoint, api_key, api_secret):
op = OnePassword()
available_vaults = op.list_vaults()
employee_vault = next((vault for vault in available_vaults if vault["name"] == "Employee"), None)
if not employee_vault:
print("No Employee vault found")
items = op.list_items(vault=employee_vault["id"])
addepar_item = next((item for item in items if item["title"] == "Addepar API"), None)
if not addepar_item:
print("Please check that Addepar API item exists in 1Password")
item_details = op.get_item(uuid=addepar_item["id"], fields=["username", "credential"])
if not item_details:
print("Please check that Addepar API item credentials exists in 1Password")
api_key = item_details["username"]
api_secret = item_details["credential"]
base_endpoint = "https://myfirm.addepar.com/api/v1/"
Ошибка пользователя ПК: >
Код: Выделить всё
C:\Users\User\PyCharmMiscProject\.venv\Scripts\python.exe C:\Users\User\PyCharmMiscProject\Main.py
⚠ Please enter an Entity ID: 123
Traceback (most recent call last):
File "C:\Users\User\PyCharmMiscProject\Main.py", line 180, in
entity_attributes = get_entity_attributes(entity_id)
File "C:\Users\User\PyCharmMiscProject\Main.py", line 32, in get_entity_attributes
base_endpoint, api_key, api_secret = authenticate(base_endpoint="", api_key="", api_secret="")
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\User\PyCharmMiscProject\Main.py", line 11, in authenticate
op = OnePassword()
File "C:\Users\User\PyCharmMiscProject\.venv\Lib\site-packages\onepassword.py", line 52, in __init__
raise MissingCredentials()
onepassword.MissingCredentials
Process finished with exit code 1
Мне удалось отследить ошибку до библиотеки onepassword, а именно до следующего файла. Я думаю, что это как-то связано с bin_path, однако, как пользователю Mac, мне сложно понять, что происходит:
Код: Выделить всё
class OnePassword(object):
def __init__(self, secret=None, token=None, shorthand=None, bin_path=""):
self.op = os.path.join(bin_path, "op")
if secret is not None:
self.shorthand = str(uuid4())
self.session_token = self.get_access_token(secret, shorthand=self.shorthand)
elif token is not None and shorthand is not None:
self.shorthand = shorthand
self.session_token = token
else:
raise MissingCredentials()
Подробнее здесь: https://stackoverflow.com/questions/793 ... on-library
Мобильная версия