RuntimeError: cryptography is required for sha256_password or caching_sha2_password
One day, trying to connect to MySQL from Python got this error.
This time we will introduce this
cryptography is required error.
cryptography is required translates to" encryption ".
What you encrypt is password used for login.
If you use
caching_sha2_password when connecting to MySQL, you are saying to encrypt passwords.
As an aside, if you are regularly running a Python program from the Windows Task Manager, this
cryptography is required may cause a
(0x1) error, so be careful.
How to fix the error
The cause of the error is Python's cryptographic library shortage.
In other words, add the encryption library with the following command and solve it.
pip install cryptography
Improve helpfulness of error message when cryptography is required · Issue # 768 · PyMySQL / PyMySQL · GitHub
Notes on Windows environment
Access rejection error occurs depending on the folder where Python is installed under Windows environment.
Choose "Run as administrator" when starting the command prompt so that access is not refused.
Right click -> Run as administrator