invalid syntax using passlib sha512_crypt
Following "Automate Server Configuration with Ansible Playbooks" Using Debian 10.
Encountered: File "<string>", line 1 from passlib.hash import sha512_crypt; print sha512_crypt.encrypt('PlainTextPassword')</string>
Tried sha512_crypt.hash instead of .encrypt. Still have the syntax error.
https://passlib.readthedocs.io/en/stable/narr/hash-tutorial.html#password-hash-examples
Still had the syntax error.
The correct usage?
2 Replies
Hey there,
We recommend opening a python repl and running this as two lines, instead of one, to avoid the syntax error:
from passlib.hash import sha512_crypt
hash = sha512_crypt.hash("password")
You can also use the following to test the hash:
sha512_crypt.verify("password", hash)
This is the process described in the original documentation for passlib that we recommend you read through first.
We hope that helps, and we'll pass the feedback along that you had trouble with the syntax to our Documentation team to take a look at. thanks for letting us know!
Sincerely,
Tara T
Linode Support Team
The code in the doc works with python 2, but if you have python 3 you have the above error. To fix, you need to use parenthesis with print. For me, the passlib also showed a deprecation warning for the encrypt method (DeprecationWarning: the method passlib.handlers.sha2_crypt.sha512_crypt.encrypt() is deprecated as of Passlib 1.7), so I ended up using this line with python 3:
sudo python -c "from passlib.hash import sha512_crypt; print(sha512_crypt.hash('myPlainTextPassword'))"
This generates the hash without any error for me.