A couple of usage questions

44 views
Skip to first unread message

Jordan Rickman

unread,
May 2, 2013, 6:41:26 AM5/2/13
to bjso...@googlegroups.com
I wasn't able to figure these out from the documentation.

(1) Some of the methods I am serving through my server need to use the IP address of the client. How can they access this information?

(2) How would I go about creating custom JSON-RPC errors, e.g. specifying the error code and message. Should I extend bjsonrpc.exceptions.ServerError?

deavid

unread,
May 2, 2013, 7:42:01 AM5/2/13
to bjso...@googlegroups.com
About your question (1): Connection classes has lots of useful information.
Maybe _sck and _address are the most useful ones for you. Take a look
to connection.py , __init__ function for a complete list of the
methods available.

If you want to access the connection from the handler, try
"self._conn", it will hold the current connection class.

About your question (2): In general, errors are sent as text. If you
are waiting some type of error, you should parse the text.
Someone already give me the idea to propagate the specific error, but
i couldn't find time to do it.

2013/5/2 Jordan Rickman <jorges...@gmail.com>:
> --
> Has recibido este mensaje porque estás suscrito al grupo "BJSONRPC" de
> Grupos de Google.
> Para anular la suscripción a este grupo y dejar de recibir sus correos
> electrónicos, envía un correo electrónico a
> bjsonrpc+u...@googlegroups.com.
> Para obtener más opciones, visita https://groups.google.com/groups/opt_out.
>
>

Jordan Rickman

unread,
May 2, 2013, 10:36:56 AM5/2/13
to bjso...@googlegroups.com
Thank you for the prompt response!

I was able to solve both of my problems. With regards to (1), I access self._conn._address[0] from within the handler.
With regards to (2), I noticed that Connection._dispatch_method will directly copy the string representation of an exception if that exception is a ServerError. So I am writing custom errors as subclasses of ServerError and overriding the __str__ method to produce a unique identifying string that my clients can parse.
These aren't optimal solutions, in that they depend on private implementation details of bjsonrpc, but they do the job. Yours is still one of the most feature-rich JSON-RPC for Python libraries I've found, and I particularly appreciate that its the only one I've found that has HTML documentation.

deavid

unread,
May 3, 2013, 2:15:59 AM5/3/13
to bjso...@googlegroups.com
2013/5/2 Jordan Rickman <jorges...@gmail.com>:
> Thank you for the prompt response!
>
> I was able to solve both of my problems. With regards to (1), I access
> self._conn._address[0] from within the handler.
> With regards to (2), I noticed that Connection._dispatch_method will
> directly copy the string representation of an exception if that exception is
> a ServerError. So I am writing custom errors as subclasses of ServerError
> and overriding the __str__ method to produce a unique identifying string
> that my clients can parse.
> These aren't optimal solutions, in that they depend on private
> implementation details of bjsonrpc, but they do the job. Yours is still one
> of the most feature-rich JSON-RPC for Python libraries I've found, and I
> particularly appreciate that its the only one I've found that has HTML
> documentation.
>

I know. Anyway those things aren't going to change. I'm using those
private methods as well.
Reply all
Reply to author
Forward
0 new messages