2

I am new to Python and Heroku. When I run the python app in heroku, I am getting below error. I tried to run the app locally and it works fine. Can anyone please help me, how to fix this.

(myvenv) C:\Users\pc\Desktop\user1\heroku_captsone>heroku run python manage.py db upgrade test-app
 »   Warning: heroku update available from 7.53.0 to 7.60.2.
Running python manage.py db upgrade test-app on ⬢ test-app... up, run.8455 (Free)
Traceback (most recent call last):
  File "manage.py", line 4, in <module>
    from app import app
  File "/app/app.py", line 12, in <module>
    from auth.auth import *
  File "/app/auth/auth.py", line 5, in <module>
    from jose import jwt
  File "/app/.heroku/python/lib/python3.7/site-packages/jose/jwt.py", line 11, in <module>
    from jose import jws
  File "/app/.heroku/python/lib/python3.7/site-packages/jose/jws.py", line 8, in <module>
    from jose import jwk
  File "/app/.heroku/python/lib/python3.7/site-packages/jose/jwk.py", line 10, in <module>
    from jose.backends.base import Key
  File "/app/.heroku/python/lib/python3.7/site-packages/jose/backends/__init__.py", line 3, in <module>
    from jose.backends.pycrypto_backend import RSAKey
  File "/app/.heroku/python/lib/python3.7/site-packages/jose/backends/pycrypto_backend.py", line 7, in <module>
    from Crypto.PublicKey import RSA
  File "/app/.heroku/python/lib/python3.7/site-packages/Crypto/PublicKey/RSA.py", line 137
    e, d, n, p, q, u = [self._key[comp] for comp in 'e', 'd', 'n', 'p', 'q', 'u']
                                                       ^
SyntaxError: invalid syntax

Below is the requirements.txt file

alembic==1.4.2
aniso8601==6.0.0
astroid==2.2.5
autopep8==1.5.2
Babel==2.8.0
Click==7.0
ecdsa==0.13.3
Flask==1.0.2
Flask-Cors==3.0.8
Flask-Migrate==2.7.0
Flask-Moment==0.9.0
Flask-RESTful==0.3.7
Flask-Script==2.0.6
Flask-SQLAlchemy==2.4.0
Flask-WTF==0.14.3
future==0.17.1
gunicorn==20.0.4
isort==4.3.18
itsdangerous==1.1.0
Jinja2==2.10.1
lazy-object-proxy==1.4.0
Mako==1.1.2
MarkupSafe==1.1.1
mccabe==0.6.1
psycopg2==2.8.5
psycopg2-binary==2.9.1
pycodestyle==2.6.0
pycryptodome==3.3.1
pylint==2.3.1
python-dateutil==2.6.0
python-editor==1.0.4
python-jose-cryptodome==1.3.2
pytz==2019.1
six==1.12.0
SQLAlchemy==1.3.3
typed-ast==1.4.2
Werkzeug==0.15.3
wrapt==1.11.1
WTForms==2.3.1

I have set python runtime version 3.7.9 but I tried with 3.8.12 as well but getting same error.

davidism
  • 121,510
  • 29
  • 395
  • 339
  • Apparently that literal `[x for x in 1, 2, 3]` syntax works in Python 2.7, but not Python 3. Looks like you're using a _very_ old library. – ChrisGPT was on strike Jul 03 '22 at 20:31
  • Which library do I need to upgrade? – Syed Peeran Jul 04 '22 at 05:00
  • That code appears to be in the absolutely _ancient_ `pycrypto` library that you probably shouldn't be using in the first place. It hasn't been updated since 2013. That is being called by (and is likely a dependency of) [`jose`](https://pypi.org/project/jose/), which is almost as old: the latest release is from late 2015. I suggest you find a different, modern library to use in place of `jose`. – ChrisGPT was on strike Jul 04 '22 at 13:23

1 Answers1

3

I had a similar problem and, in the process of finding a solution, I discovered that the latest version of python-jose-cryptodome==1.3.2 was released in 2017 and it seems it has not been updated since then. See this link https://pypi.org/project/python-jose-cryptodome/

So I uninstalled it and replaced it with the more recent python-jose 3.3.0 which was released in June of 2021. See this link https://pypi.org/project/python-jose/

Just run the following lines of code:

$ pip uninstall python-jose-cryptodome==1.3.2 This will remove the old library.

$ pip install python-jose This will install the new one

pip freeze > requirements.txt This will add the new installation to your requirements.txt file.

ifeanyiEzu
  • 31
  • 2