Issues Starting Out With Onepassword Connect & Python

nwhalnwhal
Community Member

Good evening all,
I hope this post reaches you in good health!
I am currently working on automating onepassword secrets via Python. I have the onepassword connector up & running & I can successfully pull information from it via curl as shown on this page. I also have the onepasswordconnectsdk installed via pip. However, when I attempt to test out a write to a vault via a copied & pasted section of code from the "Create Item" section present in the Python SDK documentation I receive an error stating:

NameError: name 'onepasswordconnectsdk' is not defined.

I am not sure why this is - everything looks good on my end & I can even pull vault information with this script, but I cannot create items. The following is the code I am using:
def onepass():
client_from_token: Client = new_client("http://local-ip-removed/", "token-removed")
item = onepasswordconnectsdk.models.Item(vault=ItemVault(id="vault-id-removed"),
id="test",
title="title",
category="LOGIN",
tags=["1password-connect"],
fields=[Field(value="new_user",
purpose="USERNAME")])
client.update_item("vault-id-removed", item)

Sorry for the code formatting, I was going to stick it in as "code" formatted but that made it all wonky.


1Password Version: Not Provided
Extension Version: Not Provided
OS Version: Not Provided

Comments

  • tylatyla

    Team Member

    Hey @nwhal,

    It seems like the problem is about importing the onepasswordconnectsdk. Try putting an import statement like this:

    import onepasswordconnectsdk
    from onepasswordconnectsdk.client import (Client, new_client)
    from onepasswordconnectsdk.models import (ItemVault, Field)
    

    Does this work for you?

    Thanks!

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file