Python/netrc

From mn/geo/geoit
Revision as of 16:22, 7 June 2012 by Jfb (talk | contribs)

Jump to: navigation, search

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.