-1

MY following question: How can i call auth username and password from a config file.

r = requests.get(url, auth=('username', 'password')).content

What i wish is a config file which include username, password

r = requests.get(url, auth=(MYconfig file)).content

hope any one can give me a sample.

thank you in advance

davidism
  • 121,510
  • 29
  • 395
  • 339
ABU
  • 107
  • 2
  • 3
  • 13
  • Possible duplicate of [How to read a config file using python](https://stackoverflow.com/questions/19379120/how-to-read-a-config-file-using-python) – KC. Oct 26 '18 at 01:31

1 Answers1

0

Let's say you want to use the configparser Your conf file looks like this:

[user.auth]
username = my
password = password

In your code you should use it like this :

import configparser


config = configparser.ConfigParser()
config.read("C:\myconf\defaults.cfg")

then you should get your credentials like this:

username = config.get('user.auth', 'username')
password = config.get('user.auth', 'password')
Novy
  • 1,436
  • 1
  • 14
  • 26