-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ZeroNet REST API #1137
Comments
There is no REST API, but ZeroNet using Websocket for API requests/responses/events. |
How can I use Websocket? I have a Python program and I would like to communicate with ZeroNet site. |
Here is a simple example using websocket-client: import urllib2
import re
import json
import time
import websocket
req = urllib2.Request("http://127.0.0.1:43110/1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D/", headers={"Accept" : "text/html"})
wrapper_body = urllib2.urlopen(req).read()
wrapper_key = re.search('wrapper_key = "(.*?)"', wrapper_body).group(1)
ws = websocket.create_connection("ws://127.0.0.1:43110/Websocket?wrapper_key=%s" % wrapper_key)
ws.send(json.dumps({"cmd":"siteInfo","params":{},"id":1000001}))
res = ws.recv()
print res
# {"to": 1000001, "cmd": "response", "result": {"tasks": 0, "size_limit": 10, "address": "1HeLLo4uzjaLetFx6NH3PMwFP3qbRbTf3D", ... |
If I have a javascript function on the ZeroNet page, how can I call it from Python and get a function return? |
You need a headless browser to do that, eg.: http://phantomjs.org/ |
If I understand correctly, I need to run PhantomJS from Python, which sends a request to the ZeroNet page. Is there any other way? |
@filips123 nodeJS and using a module like jsdom or directly using regex and a websocket module in python (this would require rewriting that particular function to python) |
I think PhantomJS is the easiest way, here is an example: https://github.com/HelloZeroNet/ZeroMail/blob/master/echobot/echobot.py |
It works. Thank you! |
Can I use a ZeroNet for decentralized REST API server and client? If so, how? If not, can you enable this?
The text was updated successfully, but these errors were encountered: