Process incoming JSON-RPC requests in Python

Overview
Comments
  • Avoid interpreting `KeyError` and `TypeError` as method-not-found and invalid params

    Avoid interpreting `KeyError` and `TypeError` as method-not-found and invalid params

    This addresses #72 and is targeted for the 5.0 branch. The first two commits are already included in PR #94 . A point for discussion is whether to keep AssertionErrors causing an InvalidParamsResponse. While assertions can be used for argument validation they might also simply check internal server invariants which should cause a generic server error.

    opened by st31ny 20
  • send exception message instead of

    send exception message instead of "Server error"

    When RPC methods raises an exception there is always the same reply returned:

    INFO jsonrpcclient.client.response: {"jsonrpc": "2.0", "error": {"code": -32000, "message": "Server error"}, "id": 2}

    It would be great if 'message' could contain str(exception) that was thrown by called method.

    opened by BlackZork 19
  • Add debug parameter to custom-raised exceptions

    Add debug parameter to custom-raised exceptions

    When raising a jsonrpcserver exception inside a method (such as InvalidParamsError or ApiError), pass debug=True to override the global debug setting and include the data attribute in response.

    if some_condition:
        raise InvalidParamsError("Age must be within the range 0-120", debug=True)
    

    Responds with this, regardless of global debug value:

    {"jsonrpc": "2.0", "error": {"code": -32602, "message": "Invalid parameters", "data": "Age must be within the range 0-120"}, "id": 1}
    

    Same goes for ApiError.

    opened by bcb 15
  • Permission Error in jsonrpcserver 4.1.0

    Permission Error in jsonrpcserver 4.1.0

    Hi there's a permission issue with the package published on pypi

    /tmp/jsonrpcserver-4.1.0$ find . -type f -exec ls -lha {} \;
    -rw-r--r-- 1 pippo pippo 583 Nov 15 00:09 ./README.md
    -rw-r--r-- 1 pippo pippo 4.4K Jan  6 02:07 ./CHANGELOG.md
    -rw-r--r-- 1 pippo pippo 1.3K Jan  6 02:07 ./setup.py
    -rw------- 1 pippo pippo 73 Sep 10 01:56 ./MANIFEST.in
    -rw-r--r-- 1 pippo pippo 3.0K Jan  6 00:06 ./jsonrpcserver/methods.py
    -rw-r--r-- 1 pippo pippo 151 Jan  6 00:06 ./jsonrpcserver/__init__.py
    -rw-r--r-- 1 pippo pippo 3.2K Jan  6 00:06 ./jsonrpcserver/async_dispatcher.py
    -rw------- 1 pippo pippo 921 Jan 30  2019 ./jsonrpcserver/server.py
    -rw------- 1 pippo pippo 4.1K Apr 13  2019 ./jsonrpcserver/request.py
    -rw------- 1 pippo pippo 2.2K Jan 30  2019 ./jsonrpcserver/log.py
    -rw-r--r-- 1 pippo pippo 9.2K Jan  6 02:07 ./jsonrpcserver/response.py
    -rw------- 1 pippo pippo 1.3K Jan 30  2019 ./jsonrpcserver/request-schema.json
    -rw------- 1 pippo pippo 2.1K Jan 30  2019 ./jsonrpcserver/status.py
    -rw-r--r-- 1 pippo pippo 891 Jan  6 00:06 ./jsonrpcserver/exceptions.py
    -rw-r--r-- 1 pippo pippo 9.9K Jan  6 02:07 ./jsonrpcserver/dispatcher.py
    -rw-r--r-- 1 pippo pippo 38 Jan  6 02:19 ./setup.cfg
    -rw-r--r-- 1 pippo pippo 1 Jan  6 00:49 ./jsonrpcserver.egg-info/not-zip-safe
    -rw------- 1 pippo pippo 14 Jan  6 02:19 ./jsonrpcserver.egg-info/top_level.txt
    -rw------- 1 pippo pippo 566 Jan  6 02:19 ./jsonrpcserver.egg-info/SOURCES.txt
    -rw------- 1 pippo pippo 127 Jan  6 02:19 ./jsonrpcserver.egg-info/requires.txt
    -rw------- 1 pippo pippo 1.3K Jan  6 02:19 ./jsonrpcserver.egg-info/PKG-INFO
    -rw------- 1 pippo pippo 1 Jan  6 02:19 ./jsonrpcserver.egg-info/dependency_links.txt
    -rw-r--r-- 1 pippo pippo 1.3K Jan  6 02:19 ./PKG-INFO
    -rw------- 1 pippo pippo 1.1K Sep 19  2017 ./LICENSE
    

    with the old version

    :/tmp/jsonrpcserver-4.1.0$ find ../jsonrpcserver-4.0.5/ -type f -exec ls -lha {} \;
    -rw-r--r-- 1 pippo pippo 940 Jan 30  2019 ../jsonrpcserver-4.0.5/README.md
    -rw-r--r-- 1 pippo pippo 3.5K Sep 10 01:56 ../jsonrpcserver-4.0.5/CHANGELOG.md
    -rw-r--r-- 1 pippo pippo 1.1K Sep 10 01:56 ../jsonrpcserver-4.0.5/setup.py
    -rw-r--r-- 1 pippo pippo 73 Sep 10 01:56 ../jsonrpcserver-4.0.5/MANIFEST.in
    -rw-r--r-- 1 pippo pippo 2.3K Jun 21  2019 ../jsonrpcserver-4.0.5/jsonrpcserver/methods.py
    -rw-r--r-- 1 pippo pippo 151 Jan 30  2019 ../jsonrpcserver-4.0.5/jsonrpcserver/__init__.py
    -rw-r--r-- 1 pippo pippo 3.2K Apr 13  2019 ../jsonrpcserver-4.0.5/jsonrpcserver/async_dispatcher.py
    -rw-r--r-- 1 pippo pippo 921 Jan 30  2019 ../jsonrpcserver-4.0.5/jsonrpcserver/server.py
    -rw-r--r-- 1 pippo pippo 4.1K Apr 13  2019 ../jsonrpcserver-4.0.5/jsonrpcserver/request.py
    -rw-r--r-- 1 pippo pippo 2.2K Jan 30  2019 ../jsonrpcserver-4.0.5/jsonrpcserver/log.py
    -rw-r--r-- 1 pippo pippo 8.9K Jan 30  2019 ../jsonrpcserver-4.0.5/jsonrpcserver/response.py
    -rw-r--r-- 1 pippo pippo 1.3K Jan 30  2019 ../jsonrpcserver-4.0.5/jsonrpcserver/request-schema.json
    -rw-r--r-- 1 pippo pippo 2.1K Jan 30  2019 ../jsonrpcserver-4.0.5/jsonrpcserver/status.py
    -rw-r--r-- 1 pippo pippo 9.5K Jun 22  2019 ../jsonrpcserver-4.0.5/jsonrpcserver/dispatcher.py
    -rw-r--r-- 1 pippo pippo 38 Sep 10 01:57 ../jsonrpcserver-4.0.5/setup.cfg
    -rw-r--r-- 1 pippo pippo 14 Sep 10 01:57 ../jsonrpcserver-4.0.5/jsonrpcserver.egg-info/top_level.txt
    -rw-r--r-- 1 pippo pippo 502 Sep 10 01:57 ../jsonrpcserver-4.0.5/jsonrpcserver.egg-info/SOURCES.txt
    -rw-r--r-- 1 pippo pippo 127 Sep 10 01:57 ../jsonrpcserver-4.0.5/jsonrpcserver.egg-info/requires.txt
    -rw-r--r-- 1 pippo pippo 1.7K Sep 10 01:57 ../jsonrpcserver-4.0.5/jsonrpcserver.egg-info/PKG-INFO
    -rw-r--r-- 1 pippo pippo 1 Sep 10 01:57 ../jsonrpcserver-4.0.5/jsonrpcserver.egg-info/dependency_links.txt
    -rw-r--r-- 1 pippo pippo 1.7K Sep 10 01:57 ../jsonrpcserver-4.0.5/PKG-INFO
    -rw-r--r-- 1 pippo pippo 1.1K Sep 19  2017 ../jsonrpcserver-4.0.5/LICENSE
    
    

    This causes import error in particular for

    -rw------- 1 pippo pippo 127 Jan  6 02:19 ./jsonrpcserver.egg-info/requires.txt
    -rw------- 1 pippo pippo 1.3K Jan  6 02:19 ./jsonrpcserver.egg-info/PKG-INFO
    

    vs

    -rw-r--r-- 1 pippo pippo 127 Sep 10 01:57 ../jsonrpcserver-4.0.5/jsonrpcserver.egg-info/requires.txt
    -rw-r--r-- 1 pippo pippo 1.7K Sep 10 01:57 ../jsonrpcserver-4.0.5/jsonrpcserver.egg-info/PKG-INFO
    

    can you fix it? thanks Nick

    -> chmod 0644

    Originally posted by @nicola-lunghi in https://github.com/bcb/jsonrpcserver/issues/106#issuecomment-571632418

    opened by nicola-lunghi 11
  • Upload package to conda

    Upload package to conda

    I have made a conda-build script which can be used to upload jsonrpcserver to Anaconda Cloud so it can be installed with the Conda package manager.

    The script is below. Please let me know if I can assist you in upload the package to the official channel.

    conda install -c danieljfarrell_teraview jsonrpcserver

    {% set name = "jsonrpcserver"%}
    {% set version = "4.0.4" %}
    
    package:
      name: "{{ name|lower }}"
      version: "{{ version }}"
    
    source:
      url: https://github.com/bcb/jsonrpcserver/archive/4.0.4.tar.gz
      sha256: 2ed9c08b6a3ee889fd4e752b84b4335bd1ddbe4e70a5956d4e2cf44d68fe9827
    
    build:
      number: 0
      script: "python -m pip install . --no-deps --ignore-installed -vvv "
    
    requirements:
      host:
        - python
        - apply_defaults<1
        - jsonschema>=2,<4
      run:
        - python
        - apply_defaults
        - jsonschema>=2,<4
    
    about:
      home: https://github.com/bcb/jsonrpcserver
      license: MIT License
      license_family: MIT
      license_file: 
      summary: Process JSON-RPC requests in Python
      doc_url: https://jsonrpcserver.readthedocs.io/
      dev_url: 
    
    extra:
      recipe-maintainers:
        - bcb
    
    opened by danieljfarrell 10
  • Fix HTTP transport codes

    Fix HTTP transport codes

    I think it is incorrect to specify HTTP error code 4xx on a JSON RPC error, say APIError raised.

    In this example https://github.com/bcb/jsonrpcserver/blob/master/examples/flask_server.py we will see status codes in the 400 range for JSON RPC errors even though the transport did not fail in any way.

    I think this should be a 200 as the HTTP TRANSPORT did not fail. JSON-RPC 2.0 is designed to be agnostic to the transport protocol so if the transport did its job but the RPC call itself failed, the error should be communicated inside the HTTP payload and in JSON RPC, not relaying on transport error handling mechanisms.

    https://www.simple-is-better.org/json-rpc/transport_http.html

    Additional motivation:

    External authentication handling. I return a 403 if the authentication failed. Anything that is not a 200 is not assumed to be a JSON RPC payload but something deferred outside the concern of the JSON RPC server endpoint. One exception is 202 which could be a reasonable status code for a JSON RPC notify. The dispatch method could flag this as a "notification event" that did not respond with a JSON RPC response.

    Over all I think the status_code field should be removed as it mentally connects the two things, http transport and json rpc and that should be avoided.

    opened by hholst80 9
  • allow asyncio.CancelledError to bubble out of handle_exceptions

    allow asyncio.CancelledError to bubble out of handle_exceptions

    in this case a JSON-RPC response will never be returned, but in the case of an RPC server task being cancelled while generating an RPC response we can't guarantee the response will be sent anyways

    opened by embray 8
  • Access framework HTTP Request from method

    Access framework HTTP Request from method

    This is a question as much as an issue. I have several jsonrpc methods that require db, redis, and other state/config access that would normally be passed using the the 'app' or 'request' object. What is the best method to access the parent http request and/or web app object from a method?

    It seems like its necessary to modify/create/subclass:

    I will be making these changes for use in our projects (jussi,yo,sbds,hivemind).

    I'm thinking that changing the signature of the dispatch method (and all the other methods that lead to the jsonrpc method) to also accept *args, **kwargs is the best, most modular way:

    
    async def handle(aio_http_request):
        statsd = aio_http_request.app.config['statsd_client']
        jsonrpc_request = await aio_http_request.text()
        response = await methods.dispatch(jsonrpc_request, aio_http_request, statsd=statsd)
        return web.json_response(response)
    
    

    I presume the use case for db/cache/metrics isn't rare, so I thought I would solicit your expertise and opinion about how these changes are implemented, especially if you're interested in adding my changes upstream.

    Thanks for you excellent work!

    opened by john-g-g 8
  • test response serializability early

    test response serializability early

    If a handler method returns a value that cannot be JSON-encoded, an internal server error should be generated early, so the client gets an appropriate response and other requests in the same batch still can succeed (fixes #119).

    opened by st31ny 6
  • Do a release with the Errorhandling feature

    Do a release with the Errorhandling feature

    Hi, the errorhandling feature is really useful can you do a small release to include it?

    In my code I need to extend the ApiError clas to return some custom application error codes

    Thanks Nicola Lunghi

    opened by nicola-lunghi 6
  • Use fastjsonschema instead of jsonschema

    Use fastjsonschema instead of jsonschema

    Hi. I was going to use this library in my asynchronous API, but JSON validation is too slow and takes up to a few seconds. It would be great if a faster library was used instead of jsonschema, for example, fastjsonschema.

    opened by Kaveshnikov 5
  • Support for custom parameters' validators

    Support for custom parameters' validators

    Currently, the parameters' validation is bound to

        try:
            signature(func).bind(*extract_args(request, context), **extract_kwargs(request))
        except TypeError as exc:
            return Left(InvalidParamsResult(str(exc)))
        return Right(func)
    

    in dispatcher.py

    This validation checks if the method's signature is compatible with provided parameters. However, there is no easy way to interfere in this validation, e.g. to provide own error messages, etc.

    Would be very nice to have a way to specify some custom parameters' validation callable/class/etc when annotating a method with @method decorator.

    opened by antispam2002 1
  • Support JSON-RPC 1.0

    Support JSON-RPC 1.0

    Since the server should be stateless and its an request -> reply flow it would be reasonable that the server supported both JSON-RPC 1.0 and 2.0? Just ignore the "jsonrpc": "2.0" and maybe another schema validation (no support for batch, no support for object params). The server would need to track if it was a 1.0 or 2.0 request because the response will depend on that.

    https://www.jsonrpc.org/specification_v1

    opened by hholst80 1
  • Consider merging request-schema.json into a .py file

    Consider merging request-schema.json into a .py file

    Hello,

    I've hit a little issue when using jsonrpcserver with PyInstaller:

    FileNotFoundError: [Errno 2] No such file or directory: `path-to\\jsonrpcserver\\request-schema.json'
    

    I've submitted a simple hook for PyInstaller which fixes this but I've hit similar issues with python packaging and non-py files many times in the past and I suggest you consider moving the .json data into a .py file unless there's a good reason not to - it can be a new request_schema.py or any of existing files.

    This would prevent similar problems with python packaging in various tools without requiring additional effort.

    Either way, thanks for the nice library ♥

    opened by voice-of-texnoforge 1
Flashes keyboard leds on incoming/outgoing network packets

LED Net Capture Flashes keyboard leds on incoming/outgoing network packets Usage Requires root priviledges to run usage: ledcapture.py [-h] --keyboard

Dan Habot 56 Oct 27, 2022
Start a simple TCP Listener on a specified IP Address and Port Number and receive incoming connections.

About Start a simple TCP Listener on a specified IP Address and Port Number and receive incoming connections. Download Clone using git in terminal(git

AgentGeneric 5 Feb 24, 2022
Multiple-requests-poster - A tool to send multiple requests to a particular website written in Python

Multiple-requests-poster - A tool to send multiple requests to a particular website written in Python

RLX 2 Feb 14, 2022
Light, simple RPC framework for Python

Agileutil是一个Python3 RPC框架。基于微服务架构,封装了rpc/http/orm/log等常用组件,提供了简洁的API,开发者可以很快上手,快速进行业务开发。

null 16 Nov 22, 2022
RabbitMQ asynchronous connector library for Python with built in RPC support

About RabbitMQ connector library for Python that is fully integrated with the aio-pika framework. Introduction BunnyStorm is here to simplify working

null 22 Sep 11, 2022
Discord RPC Generator With Python

Discord-RPC-Generator Thank you for using this Discord Custom RP Generator. This is 100% safe and open source. Download Discord for your computer here

null 1 Nov 9, 2021
Out-of-box Python RPC framework

typed-jsonrpc Out-of-box Python RPC framework. WIP. Make LSP easy for everyone. The conception of final usage: from typed_jsonrpc import * ls = Langu

Taine Zhao 4 Dec 28, 2021
Qobuz-rpc - A simple discord rich presence client for qobuz written in Python

qobuz-rpc A simple discord rich presence client for qobuz written in Python It's

Raphael O. 13 Dec 15, 2022
This tool extracts Credit card numbers, NTLM(DCE-RPC, HTTP, SQL, LDAP, etc), Kerberos (AS-REQ Pre-Auth etype 23), HTTP Basic, SNMP, POP, SMTP, FTP, IMAP, etc from a pcap file or from a live interface.

This tool extracts Credit card numbers, NTLM(DCE-RPC, HTTP, SQL, LDAP, etc), Kerberos (AS-REQ Pre-Auth etype 23), HTTP Basic, SNMP, POP, SMTP, FTP, IMAP, etc from a pcap file or from a live interface.

null 1.6k Jan 1, 2023
A simple implementation of an RPC toolkit

Simple RPC With Raw Sockets Repository for the Data network course project: Introduction In this project, you will attempt to code a simple implementa

Milad Samimifar 1 Mar 25, 2022
Simple app that redirect fixed URL to changing URL, configurable via POST requests

This is a basic URL redirection service. It stores associations between apps and redirection URLs, for apps with changing URLs. You can then use GET r

Maxime Weyl 2 Jan 28, 2022
🔥 Minimal performant package to asynchronously make GET requests.

Minimal performant package to asynchronously make GET requests without any dependencies other than asyncio.

Yannick Perrenet 1 Jun 1, 2022
A simple framwork to streamline the Domain Adaptation training process.

FastDA Introduction This is a simple framework for domain adaptation training. You can use it to build your own training process. It heavily relies on

Vincent Zhang 7 Nov 22, 2022
Medusa is a cross-platform agent compatible with both Python 3.8 and Python 2.7.

Medusa Medusa is a cross-platform agent compatible with both Python 3.8 and Python 2.7. Installation To install Medusa, you'll need Mythic installed o

Mythic Agents 123 Nov 9, 2022
ProtOSINT is a Python script that helps you investigate Protonmail accounts and ProtonVPN IP addresses

ProtOSINT ProtOSINT is a Python script that helps you investigate ProtonMail accounts and ProtonVPN IP addresses. Description This tool can help you i

pixelbubble 249 Dec 23, 2022
A Python tool used to automate the execution of the following tools : Nmap , Nikto and Dirsearch but also to automate the report generation during a Web Penetration Testing

?? WebMap A Python tool used to automate the execution of the following tools : Nmap , Nikto and Dirsearch but also to automate the report generation

Iliass Alami Qammouri 274 Jan 1, 2023
msgspec is a fast and friendly implementation of the MessagePack protocol for Python 3.8+

msgspec msgspec is a fast and friendly implementation of the MessagePack protocol for Python 3.8+. In addition to serialization/deserializat

Jim Crist-Harif 414 Jan 6, 2023
Minimal, self-hosted, 0-config alternative to ngrok. Caddy+OpenSSH+50 lines of Python.

If you have a webserver running on one computer (say your development laptop), and you want to expose it securely (ie HTTPS) via a public URL, SirTunnel allows you to easily do that.

Anders Pitman 423 Jan 2, 2023
NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks.

NetworkX 12k Jan 2, 2023