Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: unsupported operand type(s) for |: 'type' and 'type' #49

Open
akamming opened this issue Oct 16, 2023 · 6 comments
Open

TypeError: unsupported operand type(s) for |: 'type' and 'type' #49

akamming opened this issue Oct 16, 2023 · 6 comments

Comments

@akamming
Copy link

Describe the bug
error in the code? I tried the sample code, and i got this typerror in the library

To Reproduce

  • on a pretty clean raspberyy pi 4B (Bullseye, with sudo apt update/upgrade)
  • i installed the library with pip install 1password
  • then i ran the sample code:
from onepassword import OnePassword
import json

op = OnePassword()

# List all vaults 
json.loads(op.list_vaults())

# List all items in a vault, default is Private
op.list_items()

# Get all fields, one field or more fields for an item with uuid="example"
op.get_item(uuid="example")
op.get_item(uuid="example", fields="username")
op.get_item(uuid="example", fields=["username", "password"])`

and got this error:

pi@studeerkamer:~/1pw $ python3 backup.py
Traceback (most recent call last):
  File "/home/pi/1pw/backup.py", line 1, in <module>
    from onepassword import OnePassword
  File "/home/pi/.local/lib/python3.9/site-packages/onepassword/__init__.py", line 1, in <module>
    from .client import OnePassword
  File "/home/pi/.local/lib/python3.9/site-packages/onepassword/client.py", line 10, in <module>
    from onepassword.utils import read_bash_return, domain_from_email, Encryption, BashProfile, get_device_uuid, \
  File "/home/pi/.local/lib/python3.9/site-packages/onepassword/utils.py", line 64, in <module>
    def _spawn_signin(command, m_password) -> str | bool:
TypeError: unsupported operand type(s) for |: 'type' and 'type'

So already fails on the "from onepassword import OnePassword" line...

Expected behavior
At least to not fail on the "from onepassword import OnePassword" line

Desktop (please complete the following information):

  • OS: rapsberry pi bullseye
@dtpryce
Copy link
Collaborator

dtpryce commented Oct 16, 2023

Hey @akamming thanks for posting this issue ... it looks like you are using python 3.9 and this might be where the issue is arising. For security patching and regulatory use we have to keep our python version fairly up to date and so have implemented this library for 3.10 and higher, are you able to use this version of python?

@akamming
Copy link
Author

I am indeed on python 3.9 which is the default python for the rpi bullseye distribution. I Will check if I can upgrade easily

@dale-courtney
Copy link

Hey, team.
I'm running Python 3.11.6
When I run the following:

from onepassword import OnePassword
import json

op = OnePassword()

json.loads(op.list_vaults())

I get the error:
TypeError: the JSON object must be str, bytes or bytearray, not list

op.list_vaults() function is returning a list instead of a string. The json.loads() function expects a JSON-formatted string as input.

When I changed the code to:

vaults_json = json.dumps(op.list_vaults())
vaults_data = json.loads(vaults_json)

I do get valid vaults_data back. However, I only get back 13 vaults. I have >100 vaults in my account.

Any idea why?

Thanks in advance.
Best,
Dale

@dtpryce
Copy link
Collaborator

dtpryce commented Dec 4, 2023

Hey @dale-courtney !

Just checking the code I see that we convert the JSON output from the cli using json.loads already ... so you should just need to do op.list_vaults and you should get a list of your vaults. I will update the README to reflect this since it's clearly confusing.

In terms of the number of vaults, as I just explained we simply parse the output from op vault list --format=json which returns the default vaults you have access to: https://developer.1password.com/docs/cli/reference/management-commands/vault/#vault-list and there is no pagination that I can tell.

Hence the code will show you only the vaults you have access to with that user within that account you have authenticated with.

If you have multiple accounts or groups you might need to authenticate with them separately and bring those vaults in there.

@dtpryce
Copy link
Collaborator

dtpryce commented Dec 22, 2023

I am indeed on python 3.9 which is the default python for the rpi bullseye distribution. I Will check if I can upgrade easily

@akamming How did this go?

@dtpryce
Copy link
Collaborator

dtpryce commented Dec 22, 2023

Hey, team. I'm running Python 3.11.6 When I run the following:

from onepassword import OnePassword
import json

op = OnePassword()

json.loads(op.list_vaults())

I get the error: TypeError: the JSON object must be str, bytes or bytearray, not list

op.list_vaults() function is returning a list instead of a string. The json.loads() function expects a JSON-formatted string as input.

When I changed the code to:

vaults_json = json.dumps(op.list_vaults())
vaults_data = json.loads(vaults_json)

I do get valid vaults_data back. However, I only get back 13 vaults. I have >100 vaults in my account.

Any idea why?

Thanks in advance. Best, Dale

@dale-courtney I have moved this into a separate issue #55

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants