onepasswordpy icon indicating copy to clipboard operation
onepasswordpy copied to clipboard

Not Working?

Open Jud opened this issue 11 years ago • 3 comments

I have this code:

import os
import sys
import getpass
import onepassword.keychain

# Our password function
def get_password(msg=False):
    # Get the password
    p = getpass.getpass(prompt='1Password: ', stream=sys.stderr)
    p = False if not len(p) else p

    return p

k = onepassword.keychain.AKeychain(
        path=os.path.expanduser("~/Dropbox/1Password.agilekeychain"))

k.unlock(get_password())
print k.decrypt(keyid=k.levels['SL5'], string="My Item")

When the string "My Item" is a 1Password "Account", it doesn't print anything. When the item is a 1password "Login" item, it prints out binary data. Have I set it up incorrectly?

Jud avatar Mar 30 '13 01:03 Jud

Sorry for taking so long to respond to you.

You should be able to look through the items attribute of the AKeychain object. What do you get when you run the following:

print [(item.data['typeName'], item.data['title']) for item in k.items]`

Roguelazer avatar Apr 22 '13 01:04 Roguelazer

Ok, but how we can use data stored in k.items[1]._decrypted ? I need a password stored in encrypted section.

glushchenko avatar Aug 18 '13 11:08 glushchenko

(I realize this is an almost year old issue, but I figured lost wandering souls could make use of my findings)

It is not completely obvious how onepasswordpy should be used without digging into the source code (something that one could improve upon in the README, perhaps?).

Here's a basic script that allows me to retrieve my 1password items using onepasswordpy. Of course you'll want to change the path on line 6 to your own setup (don't forget to switch AKeychain for CKeychain if your data resides in iCloud).

Additionally, on line 18, I'm using SL5. This should be fine for most cases, but if the script doesn't work with your keychain, that might be something to investigate.

If you're looking for more than what the very basic script offers, decrypted_data should hold most of what a typical user would be looking for.

Thanks again @Roguelazer for your work on this project; looking forward to adding some contributions in the future :)

ghost avatar Jun 13 '14 19:06 ghost