stencila / py

Stencila for Python
Apache License 2.0
17 stars 1 forks source link

403 (Forbidden) error on Windows 10 #15

Closed cuibonobo closed 6 years ago

cuibonobo commented 6 years ago

I've been trying to get the Python examples in the 'Stencila Documents` guide to run, but haven't had luck yet. There are 2 problems so far:

  1. It seems like the command in py.json is never run because peer discovery is consistently failing. There is nothing listening on those ports when I start Stencila.
  2. If I run the command listed in py.json manually ("C:\Users\jgarcia\AppData\Roaming\Python\Python36\site-packages\stencila\host.py"), instead I get the following errors in my console:
GET http://127.0.0.1:2000/ 403 (FORBIDDEN) (requests.js:36)
    Promise @ requests.js:36
    request @ requests.js:19
    GET @ requests.js:42
    pokePeer @ Host.js:149
    discoverPeers @ Host.js:174
    setTimeout @ Host.js:176
Uncaught (in promise) 403: (document.html:1)

Indeed, if I visit http://127.0.0.1:2000 in my browser I get an HTTP ERROR 403. After looking at host_http_server.py I realized that I needed to supply ticket in the query string. Once I did that I could get a 200 response, but the discoverPeers() method in Host.js doesn't expect to know a ticket value, so I guess I'm at a loss for how this is supposed to work.

nokome commented 6 years ago

Hi @cuibonobo : thanks for trying this out, sorry for the problems :( It sounds like you are try to use an old version of Stencila Desktop with a newer version of the Python package. We've made some changes to the API that the two use to talk to each other, including adding a ticket for additional security.

We're planning on releasing a new, stable desktop version in a few weeks. But in the meantime, examples using the latest builds are available via http://builds.stenci.la/stencila/. You can connect these examples to the latest version of the Python package (I just made a couple of updates to ensure this works) by running it locally:

$ pip install --user https://github.com/stencila/py/archive/master.zip
$ python -m stencila
Host has started at: http://127.0.0.1:2000/?ticket=R3hwrI204ZNS
Use Ctrl+C to stop

And then pasting that url, including the ticket, into the 'hosts' panel in the user interface (accessible via the button in the bottom right corner) and creating a new Python cell e.g.

image

Let me know if that works for you, or if I can assist with anything else.

cuibonobo commented 6 years ago

Aha! What a cool way to do testing!

I've done the above but it won't let me add a host. My console says:

Failed to load http://127.0.0.1:2000/?ticket=MFjbehplXLzf: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://builds.stenci.la' is therefore not allowed access.

It seems like if the server that's being created with python -m stencila adds Access-Control-Allow-Origin: * to its headers this could work for me.

nokome commented 6 years ago

Instead of using Access-Control-Allow-Origin:* which is dangerous, we are using Access-Control-Allow-Origin:<origin> if origin is 127.0.0.1, localhost, or *.stenci.la. See https://github.com/stencila/py/blob/master/stencila/host_http_server.py#L208.

But I chaged that line a few days ago to allow *.stenci.la (instead of open.stenci.la). So wondering if you have the most recent version.

cuibonobo commented 6 years ago

Nice! I updated to the latest version and I'm now able to add hosts. I'm still having trouble though. Even though the PythonContext appears in the sidebar, it seems like there is still an API mismatch.

The Javascript is sending the following request body:

{code: "import sys↵↵sys.ver", inputs: {}, exprOnly: false}

...but then the response is a 500 error with the following body:

Traceback (most recent call last):
  File "C:\Users\jgarcia\AppData\Roaming\Python\Python36\site-packages\stencila\host_http_server.py", line 185, in handle
    response = method(request, *args)
  File "C:\Users\jgarcia\AppData\Roaming\Python\Python36\site-packages\stencila\host_http_server.py", line 330, in put
    to_json(self._host.put(name, method, kwargs)),
  File "C:\Users\jgarcia\AppData\Roaming\Python\Python36\site-packages\stencila\host.py", line 192, in put
    return func(**kwargs)
  File "C:\Users\jgarcia\AppData\Roaming\Python\Python36\site-packages\stencila\python_context.py", line 361, in executeCode
    return self.execute(*args, **kwargs)
TypeError: execute() got an unexpected keyword argument 'exprOnly'
nokome commented 6 years ago

Thanks for your patience! Things are unstable right now due to changes in the API - but it's great having someone like you willing to test things out despite the :bug:s.

I've made that fix and pushed it to master, so you could do a git pull and try again if you like. You might like to try the Jupyter notebook example which is also fixed now (you will have to type a space or something in a cell to re-execute the code:

http://builds.stenci.la/stencila/fix-jupyter-notebook-example-2018-03-20-abed47a/example.html?archive=py-jupyter

cuibonobo commented 6 years ago

Yeah, I figured things would be a little unstable, but it's a cool project which is why I'm sticking around. 😀

I don't see any new commits on master! Maybe you pushed somewhere else haha

nokome commented 6 years ago

Arrrgh, you are right, I hadn't pushed. Done now: https://github.com/stencila/py/commit/ec1f6cbbd485b6ed3b4db741263c89cf07c710dd

cuibonobo commented 6 years ago

That did it!

screenshot 2018-03-22 10 51 14

Thanks for your help!

nokome commented 6 years ago

Great! Great thanks again for your patience and please check back in a little while when things are a bit more stable (next major release of Stencila Desktop is targeted for 1 month from now).