kandi background
kandi background
Explore Kits
kandi background
Explore Kits
kandi background
Explore Kits
kandi background
Explore Kits
Explore all AWS open source software, libraries, packages, source code, cloud functions and APIs.

Popular New Releases in AWS

LocalStack release 0.14.2

v0.42.0

Release v1.43.45

Release v2.1120.0

Release 4.0.1

localstack

LocalStack release 0.14.2

cortex

v0.42.0

aws-sdk-go

Release v1.43.45

aws-sdk-js

Release v2.1120.0

troposphere

Release 4.0.1

Popular Libraries in AWS

Trending New libraries in AWS

Top Authors in AWS

1

405 Libraries

20379

2

153 Libraries

29910

3

86 Libraries

58337

4

64 Libraries

9170

5

40 Libraries

2604

6

40 Libraries

4988

7

26 Libraries

341

8

23 Libraries

621

9

23 Libraries

3051

10

17 Libraries

248

1

405 Libraries

20379

2

153 Libraries

29910

3

86 Libraries

58337

4

64 Libraries

9170

5

40 Libraries

2604

6

40 Libraries

4988

7

26 Libraries

341

8

23 Libraries

621

9

23 Libraries

3051

10

17 Libraries

248

Trending Kits in AWS

No Trending Kits are available at this moment for AWS

Trending Discussions on AWS

    Python/Docker ImportError: cannot import name 'json' from itsdangerous
    Docker push to AWS ECR hangs immediately and times out
    What is jsconfig.json
    Error: While updating laravel 8 to 9. Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
    Python Selenium AWS Lambda Change WebGL Vendor/Renderer For Undetectable Headless Scraper
    AttributeError: Can't get attribute 'new_block' on <module 'pandas.core.internals.blocks'>
    Terraform AWS Provider Error: Value for unconfigurable attribute. Can't configure a value for "acl": its value will be decided automatically
    How can I get output from boto3 ecs execute_command?
    AWS Graphql lambda query
    'AmplifySignOut' is not exported from '@aws-amplify/ui-react'

QUESTION

Python/Docker ImportError: cannot import name 'json' from itsdangerous

Asked 2022-Mar-31 at 12:49

I am trying to get a Flask and Docker application to work but when I try and run it using my docker-compose up command in my Visual Studio terminal, it gives me an ImportError called ImportError: cannot import name 'json' from itsdangerous. I have tried to look for possible solutions to this problem but as of right now there are not many on here or anywhere else. The only two solutions I could find are to change the current installation of MarkupSafe and itsdangerous to a higher version: https://serverfault.com/questions/1094062/from-itsdangerous-import-json-as-json-importerror-cannot-import-name-json-fr and another one on GitHub that tells me to essentially change the MarkUpSafe and itsdangerous installation again https://github.com/aws/aws-sam-cli/issues/3661, I have also tried to make a virtual environment named veganetworkscriptenv to install the packages but that has also failed as well. I am currently using Flask 2.0.0 and Docker 5.0.0 and the error occurs on line eight in vegamain.py.

Here is the full ImportError that I get when I try and run the program:

1veganetworkscript-backend-1  | Traceback (most recent call last):
2veganetworkscript-backend-1  |   File "/app/vegamain.py", line 8, in <module>
3veganetworkscript-backend-1  |     from flask import Flask
4veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
5veganetworkscript-backend-1  |     from . import json
6veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
7veganetworkscript-backend-1  |     from itsdangerous import json as _json
8veganetworkscript-backend-1  | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
9veganetworkscript-backend-1 exited with code 1
10

Here are my requirements.txt, vegamain.py, Dockerfile, and docker-compose.yml files:

requirements.txt:

1veganetworkscript-backend-1  | Traceback (most recent call last):
2veganetworkscript-backend-1  |   File "/app/vegamain.py", line 8, in <module>
3veganetworkscript-backend-1  |     from flask import Flask
4veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
5veganetworkscript-backend-1  |     from . import json
6veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
7veganetworkscript-backend-1  |     from itsdangerous import json as _json
8veganetworkscript-backend-1  | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
9veganetworkscript-backend-1 exited with code 1
10Flask==2.0.0
11Flask-SQLAlchemy==2.4.4
12SQLAlchemy==1.3.20
13Flask-Migrate==2.5.3
14Flask-Script==2.0.6
15Flask-Cors==3.0.9
16requests==2.25.0
17mysqlclient==2.0.1
18pika==1.1.0
19wolframalpha==4.3.0
20

vegamain.py:

1veganetworkscript-backend-1  | Traceback (most recent call last):
2veganetworkscript-backend-1  |   File "/app/vegamain.py", line 8, in <module>
3veganetworkscript-backend-1  |     from flask import Flask
4veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
5veganetworkscript-backend-1  |     from . import json
6veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
7veganetworkscript-backend-1  |     from itsdangerous import json as _json
8veganetworkscript-backend-1  | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
9veganetworkscript-backend-1 exited with code 1
10Flask==2.0.0
11Flask-SQLAlchemy==2.4.4
12SQLAlchemy==1.3.20
13Flask-Migrate==2.5.3
14Flask-Script==2.0.6
15Flask-Cors==3.0.9
16requests==2.25.0
17mysqlclient==2.0.1
18pika==1.1.0
19wolframalpha==4.3.0
20# Veganetwork (C) TetraSystemSolutions 2022
21# all rights are reserved.  
22# 
23# Author: Trevor R. Blanchard Feb-19-2022-Jul-30-2022
24#
25
26# get our imports in order first
27from flask import Flask # <-- error occurs here!!!
28
29# start the application through flask.
30app = Flask(__name__)
31
32# if set to true will return only a "Hello World" string.
33Debug = True
34
35# start a route to the index part of the app in flask.
36@app.route('/')
37def index():
38    if (Debug == True):
39        return 'Hello World!'
40    else:
41        pass
42
43# start the flask app here --->
44if __name__ == '__main__':
45    app.run(debug=True, host='0.0.0.0') 
46

Dockerfile:

1veganetworkscript-backend-1  | Traceback (most recent call last):
2veganetworkscript-backend-1  |   File "/app/vegamain.py", line 8, in <module>
3veganetworkscript-backend-1  |     from flask import Flask
4veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
5veganetworkscript-backend-1  |     from . import json
6veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
7veganetworkscript-backend-1  |     from itsdangerous import json as _json
8veganetworkscript-backend-1  | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
9veganetworkscript-backend-1 exited with code 1
10Flask==2.0.0
11Flask-SQLAlchemy==2.4.4
12SQLAlchemy==1.3.20
13Flask-Migrate==2.5.3
14Flask-Script==2.0.6
15Flask-Cors==3.0.9
16requests==2.25.0
17mysqlclient==2.0.1
18pika==1.1.0
19wolframalpha==4.3.0
20# Veganetwork (C) TetraSystemSolutions 2022
21# all rights are reserved.  
22# 
23# Author: Trevor R. Blanchard Feb-19-2022-Jul-30-2022
24#
25
26# get our imports in order first
27from flask import Flask # <-- error occurs here!!!
28
29# start the application through flask.
30app = Flask(__name__)
31
32# if set to true will return only a "Hello World" string.
33Debug = True
34
35# start a route to the index part of the app in flask.
36@app.route('/')
37def index():
38    if (Debug == True):
39        return 'Hello World!'
40    else:
41        pass
42
43# start the flask app here --->
44if __name__ == '__main__':
45    app.run(debug=True, host='0.0.0.0') 
46FROM python:3.9
47ENV PYTHONUNBUFFERED 1
48WORKDIR /app
49COPY requirements.txt /app/requirements.txt
50RUN pip install -r requirements.txt
51COPY . /app
52

docker-compose.yml:

1veganetworkscript-backend-1  | Traceback (most recent call last):
2veganetworkscript-backend-1  |   File "/app/vegamain.py", line 8, in <module>
3veganetworkscript-backend-1  |     from flask import Flask
4veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
5veganetworkscript-backend-1  |     from . import json
6veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
7veganetworkscript-backend-1  |     from itsdangerous import json as _json
8veganetworkscript-backend-1  | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
9veganetworkscript-backend-1 exited with code 1
10Flask==2.0.0
11Flask-SQLAlchemy==2.4.4
12SQLAlchemy==1.3.20
13Flask-Migrate==2.5.3
14Flask-Script==2.0.6
15Flask-Cors==3.0.9
16requests==2.25.0
17mysqlclient==2.0.1
18pika==1.1.0
19wolframalpha==4.3.0
20# Veganetwork (C) TetraSystemSolutions 2022
21# all rights are reserved.  
22# 
23# Author: Trevor R. Blanchard Feb-19-2022-Jul-30-2022
24#
25
26# get our imports in order first
27from flask import Flask # <-- error occurs here!!!
28
29# start the application through flask.
30app = Flask(__name__)
31
32# if set to true will return only a "Hello World" string.
33Debug = True
34
35# start a route to the index part of the app in flask.
36@app.route('/')
37def index():
38    if (Debug == True):
39        return 'Hello World!'
40    else:
41        pass
42
43# start the flask app here --->
44if __name__ == '__main__':
45    app.run(debug=True, host='0.0.0.0') 
46FROM python:3.9
47ENV PYTHONUNBUFFERED 1
48WORKDIR /app
49COPY requirements.txt /app/requirements.txt
50RUN pip install -r requirements.txt
51COPY . /app
52version: '3.8'
53services:
54  backend:
55    build:
56      context: .
57      dockerfile: Dockerfile
58    command: 'python vegamain.py'
59    ports:
60      - 8004:5000
61    volumes:
62      - .:/app
63    depends_on:
64      - db
65
66#  queue:
67#    build:
68#      context: .
69#      dockerfile: Dockerfile
70#    command: 'python -u consumer.py'
71#    depends_on:
72#      - db
73
74  db:
75    image: mysql:5.7.22
76    restart: always
77    environment:
78      MYSQL_DATABASE: admin
79      MYSQL_USER: root
80      MYSQL_PASSWORD: root
81      MYSQL_ROOT_PASSWORD: root
82    volumes:
83      - .dbdata:/var/lib/mysql
84    ports:
85      - 33069:3306
86

How exactly can I fix this code? thank you!

ANSWER

Answered 2022-Feb-20 at 12:31

I was facing the same issue while running docker containers with flask.

I downgraded Flask to 1.1.4 and markupsafe to 2.0.1 which solved my issue.

Check this for reference.

Source https://stackoverflow.com/questions/71189819

Community Discussions contain sources that include Stack Exchange Network

    Python/Docker ImportError: cannot import name 'json' from itsdangerous
    Docker push to AWS ECR hangs immediately and times out
    What is jsconfig.json
    Error: While updating laravel 8 to 9. Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
    Python Selenium AWS Lambda Change WebGL Vendor/Renderer For Undetectable Headless Scraper
    AttributeError: Can't get attribute 'new_block' on <module 'pandas.core.internals.blocks'>
    Terraform AWS Provider Error: Value for unconfigurable attribute. Can't configure a value for "acl": its value will be decided automatically
    How can I get output from boto3 ecs execute_command?
    AWS Graphql lambda query
    'AmplifySignOut' is not exported from '@aws-amplify/ui-react'

QUESTION

Python/Docker ImportError: cannot import name 'json' from itsdangerous

Asked 2022-Mar-31 at 12:49

I am trying to get a Flask and Docker application to work but when I try and run it using my docker-compose up command in my Visual Studio terminal, it gives me an ImportError called ImportError: cannot import name 'json' from itsdangerous. I have tried to look for possible solutions to this problem but as of right now there are not many on here or anywhere else. The only two solutions I could find are to change the current installation of MarkupSafe and itsdangerous to a higher version: https://serverfault.com/questions/1094062/from-itsdangerous-import-json-as-json-importerror-cannot-import-name-json-fr and another one on GitHub that tells me to essentially change the MarkUpSafe and itsdangerous installation again https://github.com/aws/aws-sam-cli/issues/3661, I have also tried to make a virtual environment named veganetworkscriptenv to install the packages but that has also failed as well. I am currently using Flask 2.0.0 and Docker 5.0.0 and the error occurs on line eight in vegamain.py.

Here is the full ImportError that I get when I try and run the program:

1veganetworkscript-backend-1  | Traceback (most recent call last):
2veganetworkscript-backend-1  |   File "/app/vegamain.py", line 8, in <module>
3veganetworkscript-backend-1  |     from flask import Flask
4veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
5veganetworkscript-backend-1  |     from . import json
6veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
7veganetworkscript-backend-1  |     from itsdangerous import json as _json
8veganetworkscript-backend-1  | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
9veganetworkscript-backend-1 exited with code 1
10

Here are my requirements.txt, vegamain.py, Dockerfile, and docker-compose.yml files:

requirements.txt:

1veganetworkscript-backend-1  | Traceback (most recent call last):
2veganetworkscript-backend-1  |   File "/app/vegamain.py", line 8, in <module>
3veganetworkscript-backend-1  |     from flask import Flask
4veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
5veganetworkscript-backend-1  |     from . import json
6veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
7veganetworkscript-backend-1  |     from itsdangerous import json as _json
8veganetworkscript-backend-1  | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
9veganetworkscript-backend-1 exited with code 1
10Flask==2.0.0
11Flask-SQLAlchemy==2.4.4
12SQLAlchemy==1.3.20
13Flask-Migrate==2.5.3
14Flask-Script==2.0.6
15Flask-Cors==3.0.9
16requests==2.25.0
17mysqlclient==2.0.1
18pika==1.1.0
19wolframalpha==4.3.0
20

vegamain.py:

1veganetworkscript-backend-1  | Traceback (most recent call last):
2veganetworkscript-backend-1  |   File "/app/vegamain.py", line 8, in <module>
3veganetworkscript-backend-1  |     from flask import Flask
4veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
5veganetworkscript-backend-1  |     from . import json
6veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
7veganetworkscript-backend-1  |     from itsdangerous import json as _json
8veganetworkscript-backend-1  | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
9veganetworkscript-backend-1 exited with code 1
10Flask==2.0.0
11Flask-SQLAlchemy==2.4.4
12SQLAlchemy==1.3.20
13Flask-Migrate==2.5.3
14Flask-Script==2.0.6
15Flask-Cors==3.0.9
16requests==2.25.0
17mysqlclient==2.0.1
18pika==1.1.0
19wolframalpha==4.3.0
20# Veganetwork (C) TetraSystemSolutions 2022
21# all rights are reserved.  
22# 
23# Author: Trevor R. Blanchard Feb-19-2022-Jul-30-2022
24#
25
26# get our imports in order first
27from flask import Flask # <-- error occurs here!!!
28
29# start the application through flask.
30app = Flask(__name__)
31
32# if set to true will return only a "Hello World" string.
33Debug = True
34
35# start a route to the index part of the app in flask.
36@app.route('/')
37def index():
38    if (Debug == True):
39        return 'Hello World!'
40    else:
41        pass
42
43# start the flask app here --->
44if __name__ == '__main__':
45    app.run(debug=True, host='0.0.0.0') 
46

Dockerfile:

1veganetworkscript-backend-1  | Traceback (most recent call last):
2veganetworkscript-backend-1  |   File "/app/vegamain.py", line 8, in <module>
3veganetworkscript-backend-1  |     from flask import Flask
4veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
5veganetworkscript-backend-1  |     from . import json
6veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
7veganetworkscript-backend-1  |     from itsdangerous import json as _json
8veganetworkscript-backend-1  | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
9veganetworkscript-backend-1 exited with code 1
10Flask==2.0.0
11Flask-SQLAlchemy==2.4.4
12SQLAlchemy==1.3.20
13Flask-Migrate==2.5.3
14Flask-Script==2.0.6
15Flask-Cors==3.0.9
16requests==2.25.0
17mysqlclient==2.0.1
18pika==1.1.0
19wolframalpha==4.3.0
20# Veganetwork (C) TetraSystemSolutions 2022
21# all rights are reserved.  
22# 
23# Author: Trevor R. Blanchard Feb-19-2022-Jul-30-2022
24#
25
26# get our imports in order first
27from flask import Flask # <-- error occurs here!!!
28
29# start the application through flask.
30app = Flask(__name__)
31
32# if set to true will return only a "Hello World" string.
33Debug = True
34
35# start a route to the index part of the app in flask.
36@app.route('/')
37def index():
38    if (Debug == True):
39        return 'Hello World!'
40    else:
41        pass
42
43# start the flask app here --->
44if __name__ == '__main__':
45    app.run(debug=True, host='0.0.0.0') 
46FROM python:3.9
47ENV PYTHONUNBUFFERED 1
48WORKDIR /app
49COPY requirements.txt /app/requirements.txt
50RUN pip install -r requirements.txt
51COPY . /app
52

docker-compose.yml:

1veganetworkscript-backend-1  | Traceback (most recent call last):
2veganetworkscript-backend-1  |   File "/app/vegamain.py", line 8, in <module>
3veganetworkscript-backend-1  |     from flask import Flask
4veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/__init__.py", line 19, in <module>
5veganetworkscript-backend-1  |     from . import json
6veganetworkscript-backend-1  |   File "/usr/local/lib/python3.9/site-packages/flask/json/__init__.py", line 15, in <module>
7veganetworkscript-backend-1  |     from itsdangerous import json as _json
8veganetworkscript-backend-1  | ImportError: cannot import name 'json' from 'itsdangerous' (/usr/local/lib/python3.9/site-packages/itsdangerous/__init__.py)
9veganetworkscript-backend-1 exited with code 1
10Flask==2.0.0
11Flask-SQLAlchemy==2.4.4
12SQLAlchemy==1.3.20
13Flask-Migrate==2.5.3
14Flask-Script==2.0.6
15Flask-Cors==3.0.9
16requests==2.25.0
17mysqlclient==2.0.1
18pika==1.1.0
19wolframalpha==4.3.0
20# Veganetwork (C) TetraSystemSolutions 2022
21# all rights are reserved.  
22# 
23# Author: Trevor R. Blanchard Feb-19-2022-Jul-30-2022
24#
25
26# get our imports in order first
27from flask import Flask # <-- error occurs here!!!
28
29# start the application through flask.
30app = Flask(__name__)
31
32# if set to true will return only a "Hello World" string.
33Debug = True
34
35# start a route to the index part of the app in flask.
36@app.route('/')
37def index():
38    if (Debug == True):
39        return 'Hello World!'
40    else:
41        pass
42
43# start the flask app here --->
44if __name__ == '__main__':
45    app.run(debug=True, host='0.0.0.0') 
46FROM python:3.9
47ENV PYTHONUNBUFFERED 1
48WORKDIR /app
49COPY requirements.txt /app/requirements.txt
50RUN pip install -r requirements.txt
51COPY . /app
52version: '3.8'
53services:
54  backend:
55    build:
56      context: .
57      dockerfile: Dockerfile
58    command: 'python vegamain.py'
59    ports:
60      - 8004:5000
61    volumes:
62      - .:/app
63    depends_on:
64      - db
65
66#  queue:
67#    build:
68#      context: .
69#      dockerfile: Dockerfile
70#    command: 'python -u consumer.py'
71#    depends_on:
72#      - db
73
74  db:
75    image: mysql:5.7.22
76    restart: always
77    environment:
78      MYSQL_DATABASE: admin
79      MYSQL_USER: root
80      MYSQL_PASSWORD: root
81      MYSQL_ROOT_PASSWORD: root
82    volumes:
83      - .dbdata:/var/lib/mysql
84    ports:
85      - 33069:3306
86

How exactly can I fix this code? thank you!

ANSWER

Answered 2022-Feb-20 at 12:31

I was facing the same issue while running docker containers with flask.

I downgraded Flask to 1.1.4 and markupsafe to 2.0.1 which solved my issue.

Check this for reference.

Source https://stackoverflow.com/questions/71189819