Pyzotero: a Python client for the Zotero API pyzotero.readthedocs.io
zotero

Merge pull request #259 from urschrei/shugel/push-zpmysrlupmnn

Add pyzotero test command to check Zotero connection

authored by urschrei.eurosky.social and committed by

GitHub 999b4292 4831930d

+45 -2
+1 -1
pyproject.toml
··· 1 1 [project] 2 2 name = "pyzotero" 3 - version = "1.7.2" 3 + version = "1.7.3" 4 4 description = "Python wrapper for the Zotero API" 5 5 readme = "README.md" 6 6 requires-python = ">=3.9"
+43
src/pyzotero/cli.py
··· 4 4 import sys 5 5 6 6 import click 7 + import httpx 7 8 8 9 from pyzotero import __version__, zotero 9 10 from pyzotero.zotero import chunks ··· 348 349 # Output as JSON array 349 350 click.echo(json.dumps(item_types, indent=2)) 350 351 352 + except Exception as e: 353 + click.echo(f"Error: {e!s}", err=True) 354 + sys.exit(1) 355 + 356 + 357 + @main.command() 358 + @click.pass_context 359 + def test(ctx): 360 + """Test connection to local Zotero instance. 361 + 362 + This command checks whether Zotero is running and accepting local connections. 363 + 364 + Examples: 365 + pyzotero test 366 + 367 + """ 368 + try: 369 + locale = ctx.obj.get("locale", "en-US") 370 + zot = _get_zotero_client(locale) 371 + 372 + # Call settings() to test the connection 373 + # This should return {} if Zotero is running and listening 374 + result = zot.settings() 375 + 376 + # If we get here, the connection succeeded 377 + click.echo("✓ Connection successful: Zotero is running and listening locally.") 378 + if result == {}: 379 + click.echo(" Received expected empty settings response.") 380 + else: 381 + click.echo(f" Received response: {json.dumps(result)}") 382 + 383 + except httpx.ConnectError: 384 + click.echo( 385 + "✗ Connection failed: Could not connect to Zotero.\n\n" 386 + "Possible causes:\n" 387 + " • Zotero might not be running\n" 388 + " • Local connections might not be enabled\n\n" 389 + "To enable local connections:\n" 390 + " Zotero > Settings > Advanced > Allow other applications on this computer to communicate with Zotero", 391 + err=True, 392 + ) 393 + sys.exit(1) 351 394 except Exception as e: 352 395 click.echo(f"Error: {e!s}", err=True) 353 396 sys.exit(1)
+1 -1
uv.lock
··· 784 784 785 785 [[package]] 786 786 name = "pyzotero" 787 - version = "1.7.2" 787 + version = "1.7.3" 788 788 source = { editable = "." } 789 789 dependencies = [ 790 790 { name = "bibtexparser" },