Python six.moves.configparser.DuplicateSectionError() Examples
The following are 1
code examples of six.moves.configparser.DuplicateSectionError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
six.moves.configparser
, or try the search function
.
Example #1
Source File: lp-aws-saml.py From lp-aws-saml with GNU General Public License v2.0 | 5 votes |
def aws_set_profile(profile_name, response): """ Save AWS credentials returned from Assume Role operation in ~/.aws/credentials INI file. The credentials are saved in a profile with [profile_name]. """ config_fn = os.path.expanduser("~/.aws/credentials") config = configparser.ConfigParser() config.read(config_fn) section = profile_name try: config.add_section(section) except configparser.DuplicateSectionError: pass try: os.makedirs(os.path.dirname(config_fn)) except OSError: pass config.set(section, 'aws_access_key_id', response['Credentials']['AccessKeyId']) config.set(section, 'aws_secret_access_key', response['Credentials']['SecretAccessKey']) config.set(section, 'aws_session_token', response['Credentials']['SessionToken']) with open(config_fn, 'w') as out: config.write(out)