1

I created a Python app, that you may find on GitHub. I wanted to test if I was able deploy it and chose Heroku, it's the first time I deploy something. Even if it works great locally it fails to deploy on Heroku with the following error TypeError: the JSON object must be str, not 'bytes'. It seems that the error comes from lockfile = json.load(f) in the buildpack.

Question

While reading through the errors related to json.load() a question about why does this deplomyment failed rose: is Heroku's Python buildpack solely reserved for Python 2 application ?

Heroku's unsuccessful Build Log

The full log is:

Activity Feed Build Log
ID 4d444270-f24f-461c-9079-bcd9134cec62

-----> Python app detected
 !     The latest version of Python 3 is python-3.6.5 (you are using python-3.5.2, which is unsupported).

 !     We recommend upgrading by specifying the latest version (python-3.6.5).
       Learn More: https://devcenter.heroku.com/articles/python-runtimes
-----> Installing pip
Traceback (most recent call last):

  File "/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/pipenv-to-pip", line 23, in <module>
    main()
  File "/app/tmp/buildpacks/779a8bbfbbe7e1b715476c0b23fc63a2103b3e4131eda558669aba8fb5e6e05682419376144189b29beb5dee6d7626b4d3385edb0954bffea6c67d8cf622fd51/vendor/pipenv-to-pip", line 11, in main
    lockfile = json.load(f)

  File "/app/.heroku/python/lib/python3.5/json/__init__.py", line 268, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "/app/.heroku/python/lib/python3.5/json/__init__.py", line 312, in loads
    s.__class__.__name__))

TypeError: the JSON object must be str, not 'bytes'
 !     Push rejected, failed to compile Python app 
 !     Push failed

Pipfile

I specified I wanted to use Python 3.6.5

[[source]]
url = "https://pypi.python.org/simple"

[packages]
requests = { extras = ['socks'] }

[requires]
python_version = "3.6.5"

buildpack

I chose a Python buildpack in the settings:

screenshot of the buildpack I installed

Other informations

  1. versions used :

I use Python 3.5.2. Or at least I think so ! And here are the full requirements.

  1. Former deployment attempt

I don't know but I tried to deploy the app on OpenShift. The app the log shows it failing during dependency downloads, I think it's safe to say that it's memory related. I didn't tried to increase the build memory limit to allow if to build all the way to completion yet.

  1. Checked answers

I already checked

Community
  • 1
  • 1
Alice Antoine
  • 411
  • 6
  • 17
  • @MartijnPieters I don't know as far as it part as it seems from the Heroku's log that it is part of `/app/tmp/buildpacks/779a...22fd51/vendor/pipenv-to-pip` file from Heroku which I don't have access to – Alice Antoine Jun 19 '18 at 15:42
  • @MartijnPieters Should I ask it to heroku.com ? – Alice Antoine Jun 19 '18 at 15:45
  • I see there is already a bug report: https://github.com/heroku/heroku-buildpack-python/issues/678. The issue is that only Python 3.6 or newer will accept a binary file object for `json.load()`, and Heroku's codebase requires Python 3.6 or newer. – Martijn Pieters Jun 19 '18 at 15:50

1 Answers1

1

I use Python 3.5.2.

Heroku only supports Python 2.7 and 3.6; Python 3.5 doesn't support passing a binary file to json.load(). The log you posted tells you so explicitly:

(you are using python-3.5.2, which is unsupported).

Also see heroku-buildpack-python issue #678:

pull requests accepted! Note, we officially only endorse the use of latest 2.7.x and 3.6.x.

A pull request has been submitted and accepted, upgrading to v135 should fix this. However, I'm not familiar enough with Heroku to be able to tell you if you can make that happen. I'd just upgrade your Python version to 3.6 instead.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • @AliceAntoine: OpenShift has a 3.6 container image available: https://github.com/sclorg/s2i-python-container/tree/master/3.6 (Redhat: https://access.redhat.com/containers/#/registry.access.redhat.com/rhscl/python-36-rhel7, CentOS: https://hub.docker.com/r/centos/python-36-centos7/). – Martijn Pieters Jun 19 '18 at 16:39
  • Thanks. I tried to specify the Python Runtime in the Pipfile, which I just added, but still have the same error. Do you know how to let it know I'm now using Python 3.6 ? – Alice Antoine Jun 20 '18 at 09:54