Python Flask import Error of module that isn´t being imported
Asked Answered
B

4

9

I have a flask app running in Google App Engine. Yesterday, I deployed a new version of my app where I only change the HTML style. It deployed as it was supposed to. Today, I realized that I didn't change the title for each corresponding HTML page, so I only changed the title tag in each HTML page. I deployed the app again and now I'm getting this strange error of an Import Error for a module that I have never even used. How can I fix this?

The error:

ImportError: cannot import name 'json' from 'itsdangerous' (/layers/google.python.pip/pip/lib/python3.7/site-packages/itsdangerous/__init__.py)

EDIT FEB 24, 2022:

enter image description here

as you can see, the original folder to python3.7 has been replaced with python3.9

Is this normal in GAE?

Blockhouse answered 18/2, 2022 at 13:7 Comment(0)
M
6

This issue on Flask's GitHub is related.

Either update to Flask>2, or if that's not possible pin ItsDangerous<2 and MarkupSafe<2.

To pin to lower versions in a requirements.txt file:

flask==1.1.4
itsdangerous==1.1.0
markupsafe==1.1.1
Minnaminnaminnie answered 18/2, 2022 at 17:23 Comment(5)
thank you! What had happend also was the that in the traceback, the directory says python3.7 which is the version I have always used. When I search the folder for python 3.7, Google App Engine last night had replaced it with python3.9....do you know if this always happens like this without warning?Blockhouse
Do you mean that the version of your App Engine service changed? It shouldn't as the runtime is defined on runtime configuration item from the app.yaml file.Aubervilliers
yes sir it did....the app.yaml had not changed from its original 3.7 as i had left it.....but python version 3.7 was no longer in my cloud shell....there is only 2 folders...one that says Python2.7 and Python3.9....really weird :(Blockhouse
if this happens again I suggest to write the details it on another post on Stack or even report it on Googles issue trackerAubervilliers
Thank you!! I was pulling my hair out about this error!Oyster
C
4

I had the same issue today. I was using flask=1.1.2, and when I updated the version to flask==2.0.3, the import issue was resolved.

Consol answered 18/2, 2022 at 16:31 Comment(1)
I tried this and in fact worked for fixing the issue originally stated. But later in my code I had an operation with .__dict__ property. Broke there because keys are not the same as in 1.1.2. For making things work without changing my code for the moment, stick to keep using flask=1.1.2 and added these to requirements.txt: itsdangerous==1.1.0 markupsafe==1.1.1.Broderic
F
3

This is caused by changes in Flask dependencies. Another question about this was asked on ServerFault.

You can either upgrade to Flask>2, or I had to downgrade to itsdangerous==2.0.1 if you can't do that.

Feliks answered 18/2, 2022 at 16:15 Comment(0)
R
1

the deprecation is performed with itsdangerous > 2.0.1.

Review answered 23/2, 2022 at 16:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.