Giter VIP home page Giter VIP logo

Comments (7)

JoshOrndorff avatar JoshOrndorff commented on September 13, 2024 2

The issue is single vs double quotes in the request, not with python vs javascript. I can reproduce your results using curl.

$ curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"author_rotateKeys", "id":1 }' https://dev-node.substrate.dev:9933

{"jsonrpc":"2.0","result":"0xb2e193c900159b6cf86b2dedea550030c9c912a160e1996decbd09159527d92f882739012a3bb9803e7ee4ffd72a290436735dbdd20a463db2736365c112597b9a2eca667dedde4a32180b2c6bbecb033cc7640f0683da37f3b070c3f72abb2a","id":1}


$ curl -H 'Content-Type: application/json' --data "{ 'jsonrpc':'2.0', 'method':'author_rotateKeys', 'id':1 }" https://dev-node.substrate.dev:9933

{"jsonrpc":"2.0","error":{"code":-32700,"message":"Parse error"},"id":null}

Standby and I'll dig deeper.

from substrate-node-template.

drandreaskrueger avatar drandreaskrueger commented on September 13, 2024 1

Thanks. So it's like this:

  • r = requests.post(url, data=json.dumps(payload), headers=headers)

I don't remember to have ever needed to do that, with any request call, ever. I have just looked up older code ... and found the difference. It was probably because I had always called it with json=payload, i.e. this works too:

  • r = requests.post(url, json=payload, headers=headers)

Thank you very much. And sorry to have bothered you with this.

from substrate-node-template.

riusricardo avatar riusricardo commented on September 13, 2024

Looks like the tutorial that you are taking a look to could not have the latest changes. It is maintained by @shawntabrizi
link: https://www.shawntabrizi.com/substrate/querying-substrate-storage-via-rpc/

from substrate-node-template.

riusricardo avatar riusricardo commented on September 13, 2024

Have you tried by following the original tutorial?
I would suggest to try it on JavaScript and then see if you can replicate the issue.

from substrate-node-template.

drandreaskrueger avatar drandreaskrueger commented on September 13, 2024

I would suggest you try it out:

pip3 install requests
python3 substrate_RPC-flaw.py 

I suppose, it comes from different stringification of dictionaries of JS vs Python??

The substrate RPC server should be language agnostic, and not force people to use JS, no?

Yes, this place HERE might be the wrong place. I guess it's the substrate core devs` job.

from substrate-node-template.

drandreaskrueger avatar drandreaskrueger commented on September 13, 2024

I can reproduce your results using curl.

Oh yes. Of course, that is even simpler. Well done.

It has to do with Python versus Javascript, because (while it's probably different for JS ??) ... the default way for Python to stringify its dictionaries seems to favor singlequotes '.

While the substrate RPC server is only happy with doublequotes " ??

from substrate-node-template.

JoshOrndorff avatar JoshOrndorff commented on September 13, 2024

The documentation for your preferred requests module explains what to do when the RPC you're calling needs valid JSON. https://requests.readthedocs.io/en/latest/user/quickstart/#more-complicated-post-requests (Third code snippet).

from substrate-node-template.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.