Difference between revisions of "Python/netrc"
From mn/geo/geoit
Line 14: | Line 14: | ||
Then in your ~/.netrc file include the following: | Then in your ~/.netrc file include the following: | ||
− | <source lang=' | + | <source lang='py'> |
machine smtp.gmail.com | machine smtp.gmail.com |
Revision as of 16:23, 7 June 2012
The netrc module can be a nice way to store credentials securely:
import netrc
HOST = 'smtp.gmail.com'
secrets = netrc.netrc()
username, account, password = secrets.authenticators( HOST )
Then in your ~/.netrc file include the following:
machine smtp.gmail.com
username your_username
password your_password
Make sure the mode is safe on the .netrc file, and you're set! You can easily call the netrc settings from any python script.