擅长:python、mysql、java
<p>您可以使用<a href="https://pypi.org/project/keyring/" rel="nofollow noreferrer">keyring</a>在脚本外部存储用户名和密码。命令行界面允许您获取、设置或删除存储的密码。您可以将用户名当作密码来存储,以确保其安全</p>
<pre><code>$ keyring help
Usage: keyring [get|set|del] SERVICE USERNAME
Options:
-h, help show this help message and exit
-p KEYRING_PATH, keyring-path=KEYRING_PATH
Path to the keyring backend
-b KEYRING_BACKEND, keyring-backend=KEYRING_BACKEND
Name of the keyring backend
list-backends List keyring backends and exit
disable Disable keyring and exit
</code></pre>
<p>从命令行设置服务的用户名和密码</p>
<pre><code>$ keyring set spacetracktools username
Password for 'username' in 'spacetracktools':
$ keyring set spacetracktools password
Password for 'password' in 'spacetracktools':
</code></pre>
<pre><code>import keyring
# get username and password from keyring
username = keyring.get_password("spacetracktools", "username")
password = keyring.get_password("spacetracktools", "password")
print("My username is:", username)
print("My password is:", password)
</code></pre>