1

I'm trying to use Flask and started with first example, while running the below code

from crypt import methods
from flask import Flask

app = Flask(__name__)

@app.route('/', methods=['GET'])
def hello_world():
    return "Hello world"


if __name__=='__main__':
    app.run(port=3000, debug=True)

I got the following error

ModuleNotFoundError: No module named '_crypt'

During handling of the above exception, another exception occurred

The error

davidism
  • 121,510
  • 29
  • 395
  • 339
user18848025
  • 39
  • 1
  • 7

1 Answers1

1

crypt is a Unix Specific Service, and not supported on Windows OS.

Right at the top of the docs for crypt:

34.5. crypt — Function to check Unix passwords

Platforms: Unix

Alternative is to use passlib:

from passlib.hash import md5_crypt as md5
from passlib.hash import sha256_crypt as sha256
from passlib.hash import sha512_crypt as sha512

md5_passwd = md5.encrypt(passwd, rounds=5000, implicit_rounds=True)
sha256_passwd = sha256.encrypt(passwd, rounds=5000, implicit_rounds=True)
sha512_passwd = sha512.encrypt(passwd, rounds=5000, implicit_rounds=True)
High-Octane
  • 1,104
  • 5
  • 19
  • You mean I have to add these lines into the file crypt.py – user18848025 Apr 18 '22 at 11:56
  • The first lines of the file crypt.py: import sys as _sys try: import _crypt except ModuleNotFoundError: if _sys.platform == 'win32': raise ImportError("The crypt module is not supported on Windows") else: raise ImportError("The required _crypt module was not built as part of CPython") – user18848025 Apr 18 '22 at 11:57
  • I means it's a Unix/Linux OS package and not supported in windows OS. For that I have added an alternative. – High-Octane Apr 18 '22 at 12:53
  • 2
    if you are using VS Code remove this from the top of the file: `from crypt import methods` sometimes its automatically added. – MarmiK Sep 22 '22 at 13:17