Opened 6 months ago

Last modified 2 weeks ago

#29495 new defect

Running site fails with python 2.x

Reported by: atagar Owned by: hiro
Priority: Medium Milestone:
Component: Webpages/Website Version:
Severity: Normal Keywords:
Cc: traumschule Actual Points:
Parent ID: Points:
Reviewer: Sponsor:

Description (last modified by atagar)

When running our new website with 'lektor server' python 2.x stacktraces, and fails to load 'about' pages. Hopefully I'll be able to provide a branch to pull from for future patches (#29493), but until then providing attaching a patch file you should be able to apply with 'git am 0001-Stacktrace-when-launching-lektor-server.patch'.

Child Tickets

Attachments (1)

0001-Stacktrace-when-launching-lektor-server.patch (3.5 KB) - added by atagar 6 months ago.

Download all attachments as: .zip

Change History (6)

comment:1 Changed 6 months ago by atagar

Description: modified (diff)

comment:2 Changed 6 months ago by atagar

Uggg. I got more errors running the site with python2 so finally gave up and reinstalled lektor with python3. Unfortunately the 'b' I added in the open call broke the site for python3...

Traceback (most recent call last):
  File "/home/atagar/.local/lib/lektor/lib/python3.5/site-packages/lektor/devserver.py", line 47, in build
    builder.build_all()
  File "/home/atagar/.local/lib/lektor/lib/python3.5/site-packages/lektor/builder.py", line 1141, in build_all
    prog, build_state = self.build(source, path_cache=path_cache)
  File "/home/atagar/.local/lib/lektor/lib/python3.5/site-packages/lektor/builder.py", line 1110, in build
    source=source, prog=prog)
  File "/home/atagar/.local/lib/lektor/lib/python3.5/site-packages/lektor/pluginsystem.py", line 161, in emit
    rv[plugin.id] = handler(**kwargs)
  File "/home/atagar/Desktop/tor/tpo/packages/i18n/lektor_i18n.py", line 350, in on_before_build
    f.write(content)
TypeError: a bytes-like object is required, not 'str'

I would suggest that rather than this patch we simply abort if the user is running python2. The site fails a few different, confusing ways so better to say upfront 'please run python3' rather than suggest that we support both python versions.

comment:3 Changed 6 months ago by hiro

Are you using lektor install as they describe on their webserver? Or the debian package?
I think the debian package doesn't support python2 at all. The idea is that python2 will not be supported in a few months (if I am not mistaken).

comment:4 Changed 6 months ago by atagar

Hi Hiro, I installed lector via their download instructions. Lector works under both python2 or python3, and installs under whatever the first 'python' executable in your path points to (which for most people is python2).

To reinstall lector with python3 I adjusted their install.sh a tad to instead pick the python3 executable.

The idea is that python2 will not be supported in a few months

That is incorrect. Python will cease to be supported in January 2020. Stem and Nyx remain compatible with Python 2.x and will continue to do so until the PSF drops support.


I am not suggesting that the site support python 2.x, but I am suggesting that the site should abort with a useful message saying "python 2.x is not supported". The code that errors is attempting to support both python versions which is why I spent several hours troubleshooting "why is our site broken?".

https://gitweb.torproject.org/project/web/tpo.git/tree/packages/i18n/lektor_i18n.py#n58

As others contribute to the site folks will run into this problem again and again. It would be much better if 'lector server' aborts with a message saying 'python 2.x is unsupported' rather than the confusing stacktraces it presently omits.

comment:5 Changed 2 weeks ago by pili

Maybe we can add this to our wiki on compiling the website? https://dip.torproject.org/web/tpo/wikis/Compiling-a-local-version-of-the-website

Note: See TracTickets for help on using tickets.