lektor / lektor-website

The main lektor website.
https://www.getlektor.com/
Other
160 stars 134 forks source link

openurl in Python 3 returns file-like object with bytes, not str #157

Closed hvnsweeting closed 6 years ago

hvnsweeting commented 7 years ago

I got an exception when install lektor by the install script

 $ curl -sf https://www.getlektor.com/install.sh | sh
...
Traceback (most recent call last):
  File "<stdin>", line 142, in <module>
  File "<stdin>", line 130, in main
  File "/usr/lib/python3.5/json/__init__.py", line 268, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

I'm using

$ python --version
Python 3.5.2

Reproduce with traceback of exception

$ python installer.py # extracted from the SH script 

Welcome to Lektor

This script will install Lektor on your computer.

Installing at:
  bin: /home/hvn/py35env/bin
  app: /home/hvn/.local/lib/lektor

Continue? [Yn] y
Traceback (most recent call last):
  File "installer.py", line 140, in <module>
    main()
  File "installer.py", line 128, in main
    for url in json.load(urlopen(VENV_URL))['urls']:
  File "/usr/lib/python3.5/json/__init__.py", line 268, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/usr/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))
TypeError: the JSON object must be str, not 'bytes'

A quick workaround to make it work on Python 3

 $ diff installer.py orig.py 
128c128
<     for url in json.loads(urlopen(VENV_URL).read().decode())['urls']:
---
>     for url in json.load(urlopen(VENV_URL))['urls']:

EDIT: this seems related but only fixed in 3.6 http://bugs.python.org/issue10976

nixjdm commented 6 years ago

This was fixed in https://github.com/lektor/lektor-website/commit/a434eb5333c5f05213127e8fb865b5cf5dfbf9fe#diff-4c32248575849e72bb21c9c1a2ba90d7