[Python] Extracting credentials from 1Password using onepassword python library

Discussão em 'Python' iniciado por Stack, Janeiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    I am using this python library ("OnePassword python client") in which to interact with my 1Password instance and extract API credentials from a vault named "Employee".

    Python Function:

    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/"


    This function works flawlessly on a Mac, however, PC users are getting the following error:

    PC User error:

    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 <module>

    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


    My Thoughts: I have unsuccessfully attempted to contact the developer to understand what onepassword.MissingCredentials might be refering to, however, I wonder if anyone else has come across this error before, and if so, the troubleshooting steps to resolve?

    Continue reading...

Compartilhe esta Página