Click here to Skip to main content
15,921,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
flask run --host=0.0.0.0
Usage: flask run [OPTIONS]
Try 'flask run --help' for help.

Error: While importing 'run', an ImportError was raised:

Traceback (most recent call last):
  File "/home/aalam/Flask_Blog/venv/lib/python3.10/site-packages/flask/cli.py", line 218, in locate_app
    __import__(module_name)
  File "/home/aalam/Flask_Blog/run.py", line 3, in <module>
    app = create_app()
  File "/home/aalam/Flask_Blog/flaskblog/__init__.py", line 26, in create_app
    from flaskblog.users.routes import users
  File "/home/aalam/Flask_Blog/flaskblog/users/routes.py", line 4, in <module>
    from flaskblog.models import User, Post
  File "/home/aalam/Flask_Blog/flaskblog/models.py", line 2, in <module>
    from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
ImportError: cannot import name 'TimedJSONWebSignatureSerializer' from 'itsdangerous' (/home/aalam/Flask_Blog/venv/lib/python3.10/site-packages/itsdangerous/__init__.py)


What I have tried:

I have tried to uninstall and then reinstall "itsdangerous". But the same error continues to appear.
Posted
Updated 7-Feb-23 22:12pm
v2

If I am not mistaken, "flask" Should be "Flask" with uppercase F.

This error is also emitted when there's an error in an imported module. A good way to start debugging such errors is to directly run the file with python (without flask run). Do not forget to call the app function.

Just add the following lines of code if you are using Flask's App Factory pattern[^]

if __name__ == "__main__":
    create_app().run()


After that run the app: python app.py
 
Share this answer
 
The message is telling you that it cannot find the TimedJSONWebSignatureSerializer class or module in the itsdangerous package. Check the documentation to see whether you have mis-spelled the name.
 
Share this answer
 
v2
Comments
Aalam Pratap Bedi 8-Feb-23 4:34am    
@ Richard MacCutchan what name, exactly, are you talking about?
Richard MacCutchan 8-Feb-23 4:38am    
Read my, and the error, message again, it is clear which name cannot be found.
Aalam Pratap Bedi 8-Feb-23 4:43am    
@ Richard MacCutchan yes I get the point that it is not able to find TimedJSONWebSignatureSerializer, but i am not aware what to do so that TimedJSONWebSignatureSerializer appears inside itsdangerous. Are you saying that I manually go inside itsdangerous and check that it contains TimedJSONWebSignatureSerializer?
Richard MacCutchan 8-Feb-23 4:45am    
No, I am telling you to go to the product documentation, to see why that module/class is not in the package. I assume you started by reading the documentation, so there should be a page that refers to <code<timedjsonwebsignatureserializer< code=""> and explains where it is.
Aalam Pratap Bedi 8-Feb-23 4:51am    
@Richard MacCutchan. Okay, now I get what are you saying. Well I am still not a experienced person in coding, so at time it takes me a while to understand some stuff. Can you provide me the link to the required documentation. Thanks for helping mate.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900