Problem with JSON RPC on RPI and calling a method









up vote
0
down vote

favorite












I got a raspberry pi with a json rpc server running on it. i used this module: https://github.com/bcb/jsonrpcserver



Everything is working fine when I only make a request to the following method:



@method
def ping():
return "pong"


But when I want to go further and do other functions and things like



@method
def changeDisplay():
self.led.clear_display()


Even when I do



@method 
def ping():
self.helloworld()

def helloworld():
print("helloworld")


then I get a 500 error without further explanation.



request("http://192.168.2.5:5000", "ping")


Request looks like above I am stuck and have tried many different things.



Traceback:



Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclient__init__.py", line 8, in request
return HTTPClient(endpoint).request(*args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesapply_defaultsdecorators.py", line 13, in wrapper
return function(self, *args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclient.py", line 232, in request
validate_against_schema=validate_against_schema,
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesapply_defaultsdecorators.py", line 13, in wrapper
return function(self, *args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclient.py", line 171, in send
self.validate_response(response)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclientshttp_client.py", line 48, in validate_response
raise ReceivedNon2xxResponseError(response.raw.status_code)
jsonrpcclient.exceptions.ReceivedNon2xxResponseError: Received 500 status code


Pastebin of full code:
https://pastebin.com/dgFEUBNp




UPDATE



Think it has something to do with the server not being async. All prints after server start are not printed










share|improve this question



















  • 1




    what is the request function? is it python requests?
    – Jack Herer
    Nov 11 at 10:16






  • 1




    It's a python request indeed. (from jsonrpcclient import request)
    – tijn167
    Nov 11 at 10:19






  • 1




    I meant the python requests module not a function from jsonrpcclient, but now I know, its most likely a 500 error is given because whichever function you are calling e.g. self.led.clear_display() is failing.
    – Jack Herer
    Nov 11 at 10:22







  • 1




    Made an edit. It's not in the function, because even a simple hello world which prints it is not working.
    – tijn167
    Nov 11 at 10:26






  • 1




    whats the traceback?
    – Jack Herer
    Nov 11 at 10:27














up vote
0
down vote

favorite












I got a raspberry pi with a json rpc server running on it. i used this module: https://github.com/bcb/jsonrpcserver



Everything is working fine when I only make a request to the following method:



@method
def ping():
return "pong"


But when I want to go further and do other functions and things like



@method
def changeDisplay():
self.led.clear_display()


Even when I do



@method 
def ping():
self.helloworld()

def helloworld():
print("helloworld")


then I get a 500 error without further explanation.



request("http://192.168.2.5:5000", "ping")


Request looks like above I am stuck and have tried many different things.



Traceback:



Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclient__init__.py", line 8, in request
return HTTPClient(endpoint).request(*args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesapply_defaultsdecorators.py", line 13, in wrapper
return function(self, *args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclient.py", line 232, in request
validate_against_schema=validate_against_schema,
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesapply_defaultsdecorators.py", line 13, in wrapper
return function(self, *args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclient.py", line 171, in send
self.validate_response(response)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclientshttp_client.py", line 48, in validate_response
raise ReceivedNon2xxResponseError(response.raw.status_code)
jsonrpcclient.exceptions.ReceivedNon2xxResponseError: Received 500 status code


Pastebin of full code:
https://pastebin.com/dgFEUBNp




UPDATE



Think it has something to do with the server not being async. All prints after server start are not printed










share|improve this question



















  • 1




    what is the request function? is it python requests?
    – Jack Herer
    Nov 11 at 10:16






  • 1




    It's a python request indeed. (from jsonrpcclient import request)
    – tijn167
    Nov 11 at 10:19






  • 1




    I meant the python requests module not a function from jsonrpcclient, but now I know, its most likely a 500 error is given because whichever function you are calling e.g. self.led.clear_display() is failing.
    – Jack Herer
    Nov 11 at 10:22







  • 1




    Made an edit. It's not in the function, because even a simple hello world which prints it is not working.
    – tijn167
    Nov 11 at 10:26






  • 1




    whats the traceback?
    – Jack Herer
    Nov 11 at 10:27












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I got a raspberry pi with a json rpc server running on it. i used this module: https://github.com/bcb/jsonrpcserver



Everything is working fine when I only make a request to the following method:



@method
def ping():
return "pong"


But when I want to go further and do other functions and things like



@method
def changeDisplay():
self.led.clear_display()


Even when I do



@method 
def ping():
self.helloworld()

def helloworld():
print("helloworld")


then I get a 500 error without further explanation.



request("http://192.168.2.5:5000", "ping")


Request looks like above I am stuck and have tried many different things.



Traceback:



Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclient__init__.py", line 8, in request
return HTTPClient(endpoint).request(*args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesapply_defaultsdecorators.py", line 13, in wrapper
return function(self, *args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclient.py", line 232, in request
validate_against_schema=validate_against_schema,
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesapply_defaultsdecorators.py", line 13, in wrapper
return function(self, *args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclient.py", line 171, in send
self.validate_response(response)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclientshttp_client.py", line 48, in validate_response
raise ReceivedNon2xxResponseError(response.raw.status_code)
jsonrpcclient.exceptions.ReceivedNon2xxResponseError: Received 500 status code


Pastebin of full code:
https://pastebin.com/dgFEUBNp




UPDATE



Think it has something to do with the server not being async. All prints after server start are not printed










share|improve this question















I got a raspberry pi with a json rpc server running on it. i used this module: https://github.com/bcb/jsonrpcserver



Everything is working fine when I only make a request to the following method:



@method
def ping():
return "pong"


But when I want to go further and do other functions and things like



@method
def changeDisplay():
self.led.clear_display()


Even when I do



@method 
def ping():
self.helloworld()

def helloworld():
print("helloworld")


then I get a 500 error without further explanation.



request("http://192.168.2.5:5000", "ping")


Request looks like above I am stuck and have tried many different things.



Traceback:



Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclient__init__.py", line 8, in request
return HTTPClient(endpoint).request(*args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesapply_defaultsdecorators.py", line 13, in wrapper
return function(self, *args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclient.py", line 232, in request
validate_against_schema=validate_against_schema,
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesapply_defaultsdecorators.py", line 13, in wrapper
return function(self, *args, **kwargs)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclient.py", line 171, in send
self.validate_response(response)
File "C:UsersTijnPycharmProjectsJSONrpcTestvenvlibsite-packagesjsonrpcclientclientshttp_client.py", line 48, in validate_response
raise ReceivedNon2xxResponseError(response.raw.status_code)
jsonrpcclient.exceptions.ReceivedNon2xxResponseError: Received 500 status code


Pastebin of full code:
https://pastebin.com/dgFEUBNp




UPDATE



Think it has something to do with the server not being async. All prints after server start are not printed







python request raspberry-pi raspberry-pi3 json-rpc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 13:02

























asked Nov 11 at 10:03









tijn167

239




239







  • 1




    what is the request function? is it python requests?
    – Jack Herer
    Nov 11 at 10:16






  • 1




    It's a python request indeed. (from jsonrpcclient import request)
    – tijn167
    Nov 11 at 10:19






  • 1




    I meant the python requests module not a function from jsonrpcclient, but now I know, its most likely a 500 error is given because whichever function you are calling e.g. self.led.clear_display() is failing.
    – Jack Herer
    Nov 11 at 10:22







  • 1




    Made an edit. It's not in the function, because even a simple hello world which prints it is not working.
    – tijn167
    Nov 11 at 10:26






  • 1




    whats the traceback?
    – Jack Herer
    Nov 11 at 10:27












  • 1




    what is the request function? is it python requests?
    – Jack Herer
    Nov 11 at 10:16






  • 1




    It's a python request indeed. (from jsonrpcclient import request)
    – tijn167
    Nov 11 at 10:19






  • 1




    I meant the python requests module not a function from jsonrpcclient, but now I know, its most likely a 500 error is given because whichever function you are calling e.g. self.led.clear_display() is failing.
    – Jack Herer
    Nov 11 at 10:22







  • 1




    Made an edit. It's not in the function, because even a simple hello world which prints it is not working.
    – tijn167
    Nov 11 at 10:26






  • 1




    whats the traceback?
    – Jack Herer
    Nov 11 at 10:27







1




1




what is the request function? is it python requests?
– Jack Herer
Nov 11 at 10:16




what is the request function? is it python requests?
– Jack Herer
Nov 11 at 10:16




1




1




It's a python request indeed. (from jsonrpcclient import request)
– tijn167
Nov 11 at 10:19




It's a python request indeed. (from jsonrpcclient import request)
– tijn167
Nov 11 at 10:19




1




1




I meant the python requests module not a function from jsonrpcclient, but now I know, its most likely a 500 error is given because whichever function you are calling e.g. self.led.clear_display() is failing.
– Jack Herer
Nov 11 at 10:22





I meant the python requests module not a function from jsonrpcclient, but now I know, its most likely a 500 error is given because whichever function you are calling e.g. self.led.clear_display() is failing.
– Jack Herer
Nov 11 at 10:22





1




1




Made an edit. It's not in the function, because even a simple hello world which prints it is not working.
– tijn167
Nov 11 at 10:26




Made an edit. It's not in the function, because even a simple hello world which prints it is not working.
– tijn167
Nov 11 at 10:26




1




1




whats the traceback?
– Jack Herer
Nov 11 at 10:27




whats the traceback?
– Jack Herer
Nov 11 at 10:27












1 Answer
1






active

oldest

votes

















up vote
1
down vote













The methods of your class do not receive a self parameter, yet attempt to use it:



class Bartender(MenuDelegate):
...
@method
def ping():
self.changeDsplay() # name `self` is not defined
print (" TOkm")
return " ewa"


The docs for jsonrpcserver and the source do not suggest that method can properly handle classes and their methods. It seems that you have to add the bound methods an instance, not the unbound methods of the class.



class Bartender(MenuDelegate):
...
# regular unbound method taking `self` parameter
def ping(self):
self.changeDsplay()
print (" TOkm")
return " ewa"

def run(self):
# register bound methods *of this instance*
method(ping=self.ping)
...





share|improve this answer






















  • Sorry, was a tryout. In my original code ping did receive a self param. Only difference is that it outputs a 400 error
    – tijn167
    Nov 11 at 13:18










  • @tijn167 Neither the code on pastebin nor in your answer show that. Please post your actual code! Also take a look at the registration of bound methods I added.
    – MisterMiyagi
    Nov 11 at 13:19











  • Tried your method, still nothing changed. Think it has something to do with using non async. Because everything after server start isn't executed
    – tijn167
    Nov 11 at 14:12










  • Your method did in fact work with a little tweak. I also started the server in the run method and thats what did the job. Now just got too check if the physical and mobile work together. Thanks!
    – tijn167
    Nov 11 at 14:37










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247618%2fproblem-with-json-rpc-on-rpi-and-calling-a-method%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













The methods of your class do not receive a self parameter, yet attempt to use it:



class Bartender(MenuDelegate):
...
@method
def ping():
self.changeDsplay() # name `self` is not defined
print (" TOkm")
return " ewa"


The docs for jsonrpcserver and the source do not suggest that method can properly handle classes and their methods. It seems that you have to add the bound methods an instance, not the unbound methods of the class.



class Bartender(MenuDelegate):
...
# regular unbound method taking `self` parameter
def ping(self):
self.changeDsplay()
print (" TOkm")
return " ewa"

def run(self):
# register bound methods *of this instance*
method(ping=self.ping)
...





share|improve this answer






















  • Sorry, was a tryout. In my original code ping did receive a self param. Only difference is that it outputs a 400 error
    – tijn167
    Nov 11 at 13:18










  • @tijn167 Neither the code on pastebin nor in your answer show that. Please post your actual code! Also take a look at the registration of bound methods I added.
    – MisterMiyagi
    Nov 11 at 13:19











  • Tried your method, still nothing changed. Think it has something to do with using non async. Because everything after server start isn't executed
    – tijn167
    Nov 11 at 14:12










  • Your method did in fact work with a little tweak. I also started the server in the run method and thats what did the job. Now just got too check if the physical and mobile work together. Thanks!
    – tijn167
    Nov 11 at 14:37














up vote
1
down vote













The methods of your class do not receive a self parameter, yet attempt to use it:



class Bartender(MenuDelegate):
...
@method
def ping():
self.changeDsplay() # name `self` is not defined
print (" TOkm")
return " ewa"


The docs for jsonrpcserver and the source do not suggest that method can properly handle classes and their methods. It seems that you have to add the bound methods an instance, not the unbound methods of the class.



class Bartender(MenuDelegate):
...
# regular unbound method taking `self` parameter
def ping(self):
self.changeDsplay()
print (" TOkm")
return " ewa"

def run(self):
# register bound methods *of this instance*
method(ping=self.ping)
...





share|improve this answer






















  • Sorry, was a tryout. In my original code ping did receive a self param. Only difference is that it outputs a 400 error
    – tijn167
    Nov 11 at 13:18










  • @tijn167 Neither the code on pastebin nor in your answer show that. Please post your actual code! Also take a look at the registration of bound methods I added.
    – MisterMiyagi
    Nov 11 at 13:19











  • Tried your method, still nothing changed. Think it has something to do with using non async. Because everything after server start isn't executed
    – tijn167
    Nov 11 at 14:12










  • Your method did in fact work with a little tweak. I also started the server in the run method and thats what did the job. Now just got too check if the physical and mobile work together. Thanks!
    – tijn167
    Nov 11 at 14:37












up vote
1
down vote










up vote
1
down vote









The methods of your class do not receive a self parameter, yet attempt to use it:



class Bartender(MenuDelegate):
...
@method
def ping():
self.changeDsplay() # name `self` is not defined
print (" TOkm")
return " ewa"


The docs for jsonrpcserver and the source do not suggest that method can properly handle classes and their methods. It seems that you have to add the bound methods an instance, not the unbound methods of the class.



class Bartender(MenuDelegate):
...
# regular unbound method taking `self` parameter
def ping(self):
self.changeDsplay()
print (" TOkm")
return " ewa"

def run(self):
# register bound methods *of this instance*
method(ping=self.ping)
...





share|improve this answer














The methods of your class do not receive a self parameter, yet attempt to use it:



class Bartender(MenuDelegate):
...
@method
def ping():
self.changeDsplay() # name `self` is not defined
print (" TOkm")
return " ewa"


The docs for jsonrpcserver and the source do not suggest that method can properly handle classes and their methods. It seems that you have to add the bound methods an instance, not the unbound methods of the class.



class Bartender(MenuDelegate):
...
# regular unbound method taking `self` parameter
def ping(self):
self.changeDsplay()
print (" TOkm")
return " ewa"

def run(self):
# register bound methods *of this instance*
method(ping=self.ping)
...






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 11 at 13:18

























answered Nov 11 at 13:08









MisterMiyagi

7,2142040




7,2142040











  • Sorry, was a tryout. In my original code ping did receive a self param. Only difference is that it outputs a 400 error
    – tijn167
    Nov 11 at 13:18










  • @tijn167 Neither the code on pastebin nor in your answer show that. Please post your actual code! Also take a look at the registration of bound methods I added.
    – MisterMiyagi
    Nov 11 at 13:19











  • Tried your method, still nothing changed. Think it has something to do with using non async. Because everything after server start isn't executed
    – tijn167
    Nov 11 at 14:12










  • Your method did in fact work with a little tweak. I also started the server in the run method and thats what did the job. Now just got too check if the physical and mobile work together. Thanks!
    – tijn167
    Nov 11 at 14:37
















  • Sorry, was a tryout. In my original code ping did receive a self param. Only difference is that it outputs a 400 error
    – tijn167
    Nov 11 at 13:18










  • @tijn167 Neither the code on pastebin nor in your answer show that. Please post your actual code! Also take a look at the registration of bound methods I added.
    – MisterMiyagi
    Nov 11 at 13:19











  • Tried your method, still nothing changed. Think it has something to do with using non async. Because everything after server start isn't executed
    – tijn167
    Nov 11 at 14:12










  • Your method did in fact work with a little tweak. I also started the server in the run method and thats what did the job. Now just got too check if the physical and mobile work together. Thanks!
    – tijn167
    Nov 11 at 14:37















Sorry, was a tryout. In my original code ping did receive a self param. Only difference is that it outputs a 400 error
– tijn167
Nov 11 at 13:18




Sorry, was a tryout. In my original code ping did receive a self param. Only difference is that it outputs a 400 error
– tijn167
Nov 11 at 13:18












@tijn167 Neither the code on pastebin nor in your answer show that. Please post your actual code! Also take a look at the registration of bound methods I added.
– MisterMiyagi
Nov 11 at 13:19





@tijn167 Neither the code on pastebin nor in your answer show that. Please post your actual code! Also take a look at the registration of bound methods I added.
– MisterMiyagi
Nov 11 at 13:19













Tried your method, still nothing changed. Think it has something to do with using non async. Because everything after server start isn't executed
– tijn167
Nov 11 at 14:12




Tried your method, still nothing changed. Think it has something to do with using non async. Because everything after server start isn't executed
– tijn167
Nov 11 at 14:12












Your method did in fact work with a little tweak. I also started the server in the run method and thats what did the job. Now just got too check if the physical and mobile work together. Thanks!
– tijn167
Nov 11 at 14:37




Your method did in fact work with a little tweak. I also started the server in the run method and thats what did the job. Now just got too check if the physical and mobile work together. Thanks!
– tijn167
Nov 11 at 14:37

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247618%2fproblem-with-json-rpc-on-rpi-and-calling-a-method%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto