Forum Discussion

CentredK's avatar
CentredK
New Contributor
12 months ago

Using a Python subprocess in WSL to create an item in a vault hangs when capuring output

I have a python script that I use to batch create items in vault within ubuntu under WSL. Works in general - Creating Vaults, reading items etc. except for creating an item in an existing vault whilst capturing - it hangs in some kind of loop and has to be aborted.

I am calling op.exe because I want to call the windows command line client - we are generally using Microsoft SSO, so you can't use the ubuntu command line client by itself.

  • Windows 11
  • WSL2
  • Description: Ubuntu 24.04 LTS
  • 1Password for Windows 8.10.45
  • OP command line 2.29.0
  • Python 3.12.3

Note that '---' below is the python prompt '>>>' - I couldn't figure out how to escape it.

```python
(flow_pass) root@Ansible:~# python3
Python 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
import subprocess

Create vault and capture output

---subprocess.run (['op.exe', 'vault', 'create', 'TestVault4'],capture_output=True)
CompletedProcess(args=['op.exe', 'vault', 'create', 'TestVault4'], returncode=0, stdout=b'ID: ianbnf5qlqp7thpobob4izqc4i\nName: TestVault4\nType: USER_CREATED\nAttribute version: 1\nContent version: 1\nItems: 0\nCreated: now\nUpdated: now\n', stderr=b'')

Create item within the vaut - don't capture output

---subprocess.run(['op.exe', 'item', 'create', '--vault', 'TestVault4', '--category', 'Login', '--title', 'TestItem4.1'],capture_output=False)
ID: sm4yuum3ztuwc3qqjm3uoqwamq
Title: TestItem4.1
Vault: TestVault4 (ianbnf5qlqp7thpobob4izqc4i)
Created: now
Updated: now
Favorite: false
Version: 1
Category: LOGIN
CompletedProcess(args=['op.exe', 'item', 'create', '--vault', 'TestVault4', '--category', 'Login', '--title', 'TestItem4.1'], returncode=0)

Create item but capture output

---subprocess.run(['op.exe', 'item', 'create', '--vault', 'TestVault4', '--category', 'Login', '--title', 'TestItem4.2'],capture_output=True)
^CTraceback (most recent call last):
File "", line 1, in
File "/usr/lib/python3.12/subprocess.py", line 550, in run
stdout, stderr = process.communicate(input, timeout=timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/subprocess.py", line 1209, in communicate
stdout, stderr = self._communicate(input, endtime, timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/subprocess.py", line 2115, in _communicate
ready = selector.select(timeout)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/selectors.py", line 415, in select
fd_event_list = self._selector.poll(timeout)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt
```

My account doesn't use SSO, so i can set up the Ububtu CLI and use that. Creating items whilst capturing the output works OK


(flow_pass) root@Ansible:~# python3
Python 3.12.3 (main, Jul 31 2024, 17:43:48) [GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
--- import subprocess
--- subprocess.run (['op', 'vault', 'create', 'TestVault5'],capture_output=True)
CompletedProcess(args=['op', 'vault', 'create', 'TestVault5'], returncode=0, stdout=b'ID: gbungw3houcos7ln5scff4lt7a\nName: TestVault5\nType: USER_CREATED\nAttribute version: 1\nContent version: 1\nItems: 0\nCreated: now\nUpdated: now\n', stderr=b'')
--- subprocess.run(['op', 'item', 'create', '--vault', 'TestVault5', '--category', 'Login', '--title', 'TestItem5.2'],capture_output=True)
CompletedProcess(args=['op', 'item', 'create', '--vault', 'TestVault5', '--category', 'Login', '--title', 'TestItem5.2'], returncode=0, stdout=b'ID: yrw4googgp62ppcqd6axjz7zyu\nTitle: TestItem5.2\nVault: TestVault5 (gbungw3houcos7ln5scff4lt7a)\nCreated: now\nUpdated: now\nFavorite: false\nVersion: 1\nCategory: LOGIN\n', stderr=b'')


1Password Version: 8.10.45
Extension Version: Not Provided
OS Version: Windows 11
Browser: Not Provided

No RepliesBe the first to reply