Difference between revisions of "Python/netrc"

From mn/geo/geoit
Jump to: navigation, search
(Created page with "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.authentica...")
 
Line 1: Line 1:
 
The netrc module can be a nice way to store credentials securely:
 
The netrc module can be a nice way to store credentials securely:
  
 +
 +
<source lang='py'>
  
 
import netrc
 
import netrc
Line 7: Line 9:
 
secrets = netrc.netrc()
 
secrets = netrc.netrc()
 
username, account, password = secrets.authenticators( HOST )
 
username, account, password = secrets.authenticators( HOST )
 +
</source>
  
  
 
Then in your ~/.netrc file include the following:
 
Then in your ~/.netrc file include the following:
  
 +
<source>
  
 
machine smtp.gmail.com
 
machine smtp.gmail.com
 
         username your_username
 
         username your_username
 
         password your_password
 
         password your_password
 +
</source>
  
  
 
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.
 
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.

Revision as of 16:21, 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.