On Sun, 30 Dec 2018, Andrew Back wrote:
> Hello,
Hi Andrew!
> I've put together a Docker container with TiddlyWebWiki running via
> twanager server and it seems to work up until the point of attempting to
> save a tiddler, which results in "Error saving New Tiddler: connection
> could not be established" and a WSGI error in the server logs, details of
> which can be found at the bottom of this message.
The root of the problem here is a combination of cheroot (the newer
cherrypy webserver used by the tiddlywebplugins.cherrypy package)
being strictly aligned with pep 3333 when it comes to headers (and
enforcing it) and selector (the URL routing library used by
tiddlyweb) decoding each line (to unicode) when it reads the
urls.map file.
The result of this is that when you make a request to tiddlyweb that
causes a 405 response, the value in the 'Allowed' header is being
sent, while in python 2.7, as unicode, not a str. According to PEP
3333, header values should always be whatever the native 'str' type
is. This was likely a horrible decision as it means the values need
to be different between Python 2 and 3.
If you have the option of using the python:3-alpine base for your
docker image, that will make the problem go away without needing to
change selector or cheroot. However you don't really have that
option until some changes are made:
* tiddlywebwiki hasn't been updated for Python 3, yet. I suppose I
should do that at some point but I wasn't aware of anyone using
it. Since you seem to be using it, that might be the push I need,
so that people don't need to use Python 2.
* tiddlywebplugins.urls also has some issues with not supporting
Python 3. For that you'll have to contact bengillies, probably via
an issue on
https://github.com/bengillies/tiddlywebplugins.urls
If he not interested but wants to transfer the repo and pypi
ownership to the tiddlyweb org and me that would be fine.
Another option would be to fix selector so that its behavior is
better when sending headers. I've looked at this but I'm not sure it
is worth doing given it works in python3 and the limited lifetime
remaining on python2.
So until those things are fixed that leaves us with hacks. I've
tried this modification to the Docker file and it seems to work:
-=-=-
FROM python:2-alpine
MAINTAINER Andrew Back <
and...@abopen.com>
VOLUME /data
RUN mkdir /usr/src/tww
COPY . /usr/src/tww
WORKDIR /usr/src/tww
RUN pip install -r requirements.txt
# hack up selector to remove line encoding
RUN sed -i'' -e '/line\.decode/d' $(python -c 'import sys; import selector; print(sys.modules["selector"].__file__)' | sed -e 's/c$//')
ENTRYPOINT ["/usr/src/tww/entrypoint.sh"]
EXPOSE 80
-=-=-
Note, however, that as done, this tiddlywiki this container presents
can only be accessed as
http://0.0.0.0/ . If you try to use
localhost or a different port, the tiddlers won't save (because the
server.host field will be
http://0.0.0.0/).
To use something different you'll need to create a
tiddlywebconfig.py with the values you want to create that url,
see:
https://tank.peermore.com/tanks/tiddlyweb/server_host
Another potential fix is to use an older version of cherrypy, by
changing tiddlywebplugins.cherrypy and CherryPy in the
requiements.txt as follows:
-=-=-
setuptools
tiddlywebwiki
tiddlywebplugins.form
tiddlywebplugins.urls
tiddlywebplugins.cherrypy==0.1.1
CherryPy==8.9.1
-=-=-
(Usual caveats about using old stuff potentially having security
issues.)
But long term you should start thinking in terms of Python 3, so
I'll see about making tiddlywebwiki python3 compatible.
I suppose it might also be time to start considering TiddlyWiki 5,
which can talk to tiddlyweb without the need for tiddlywebwiki.
In any case, I hope some of the above is useful. And Happy New Year.
--
Chris Dent
https://anticdent.org/
[...]