Registry / http-networking / jsonrpclib

jsonrpclib

JSON →
library0.2.1pypypi✓ verified 22d ago

jsonrpclib is a Python client library implementing the JSON-RPC v2.0 specification, with backwards compatibility considerations. It focuses on providing client-side functionality for interacting with JSON-RPC servers. The current version is 0.2.1. The project has seen limited updates since 2021; for more active development or server-side functionality, consider `jsonrpclib-pelix`.

pip install jsonrpclib
INSTALL
IMPORT
SIG · JSONRPCLIB
J
jsonrpclib
http-networkingpythonv0.2.1
Install
1.5s avg
Import
84ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.086s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.082s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Server
from jsonrpclib import Server

This example shows how to create a client proxy and call methods on a remote JSON-RPC server. It requires a server to be running at `SERVER_URL` for the calls to succeed. Error handling for connection issues is included.

import os from jsonrpclib import Server # This quickstart demonstrates client-side usage. # A JSON-RPC server must be running at the specified URL for this code to connect and execute. # For demonstration purposes, we use a placeholder URL. # Replace with your actual server URL or set via environment variable. SERVER_URL = os.environ.get('JSONRPCLIB_SERVER_URL', 'http://localhost:8080/jsonrpc') try: # Create a server proxy server = Server(SERVER_URL) # Example: Call a simple method (e.g., 'add' with two arguments) # The actual methods available depend on the connected JSON-RPC server. print(f"Attempting to call 'add(5, 3)' on {SERVER_URL}...") # This call will fail if no server is running or if the method doesn't exist. result_add = server.add(5, 3) print(f"Result of server.add(5, 3): {result_add}") # Example: Access a method within a namespace (if supported by the server) # e.g., 'system.get_info()' print(f"Attempting to call 'system.get_info()' on {SERVER_URL}...") # This call will fail if no server is running or if the namespace/method doesn't exist. system_info = server.system.get_info() print(f"System info from server.system.get_info(): {system_info}") except Exception as e: print(f"Error connecting to or calling JSON-RPC server at {SERVER_URL}: {e}") print("Please ensure a JSON-RPC server is running at the specified URL and provides the called methods.")
Debug
Known issues
breakingPython 2 support was officially dropped in version 0.1.0. Older versions of `jsonrpclib` were Python 2 compatible, but the current maintainer has transitioned to Python 3 exclusively.
fix
Ensure your environment is running Python 3.5+ (as per `requires_python` in `setup.py`). Migrate any Python 2 specific code if upgrading from a very old version.
affects: All versions from 0.1.0 onwards.
gotchajsonrpclib is a client-only library. It does not provide functionality for implementing a JSON-RPC server. Attempts to use it for server-side logic will fail.
fix
If you need to implement a JSON-RPC server, consider using libraries specifically designed for server-side RPC, such as `jsonrpclib-pelix` (from the same author) or other Python web frameworks with JSON-RPC extensions.
affects: All versions.
gotchaThe `jsonrpclib` project has not seen significant updates or active maintenance since April 2021. For new projects or if active development, bug fixes, or server-side functionality are critical, consider using `jsonrpclib-pelix`.
fix
Evaluate `jsonrpclib-pelix` (available on PyPI) as a more actively maintained and feature-rich alternative that also supports server implementations.
affects: All versions, especially 0.2.1.
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'jsonrpclib'
The `jsonrpclib` package is not installed in your Python environment.
fix
Run `pip install jsonrpclib` in your terminal to install the library.
AttributeError: 'SafeTransport' object has no attribute 'context'
This error typically occurs when using `jsonrpclib` (version 0.2.1) with Python 3, as the original library has limited Python 3 compatibility and relies on `xmlrpclib` (which was renamed to `xmlrpc.client` and had API changes in Python 3).
fix
For Python 3, it is recommended to use the `jsonrpclib-pelix` fork. Install it using `pip install jsonrpclib-pelix` and update your imports from `jsonrpclib` to `jsonrpclib_pelix`.
jsonrpclib.jsonrpc.ProtocolError
This exception is raised when the JSON-RPC server returns a response that does not conform to the JSON-RPC specification, or there's an issue with the underlying HTTP/HTTPS transport.
fix
Inspect the raw HTTP response from the server to identify the malformed aspect. Ensure the server is sending valid JSON-RPC 2.0 responses. Check network connectivity or server availability if it's a transport-layer issue.
JSON-RPC Server Errors (e.g., -32700: Parse error, -32601: Method not found, -32602: Invalid params)
These are standard JSON-RPC 2.0 error codes returned by the server, indicating a problem with the client's RPC request (e.g., wrong method name, incorrect parameters, or malformed request JSON) or an internal server issue.
fix
Consult the server's API documentation to verify the correct method names, required parameters, and their expected types. Ensure your client's request body strictly adheres to the JSON-RPC 2.0 specification for requests.
Upgrade
Version history
0.2.1latest on PyPI · released Mar 31, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
jsonrpclib — pip install jsonrpclib · libregistry