ModuleNotFoundError: No module named '_crypt'

Viewed 1733

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

1 Answers

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)
Related