Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python烧瓶REST验证_Python_Authentication_Python Requests - Fatal编程技术网

Python烧瓶REST验证

Python烧瓶REST验证,python,authentication,python-requests,Python,Authentication,Python Requests,我的以下问题: 如何从配置文件调用auth username和password r = requests.get(url, auth=('username', 'password')).content 我的愿望是 包含用户名、密码和密码的配置文件 r = requests.get(url, auth=(MYconfig file)).content 希望有人能给我一个样品 提前感谢您假设您想使用 您的conf文件如下所示: [user.auth] username = my password

我的以下问题: 如何从配置文件调用auth username和password

r = requests.get(url, auth=('username', 'password')).content
我的愿望是 包含用户名、密码和密码的配置文件

r = requests.get(url, auth=(MYconfig file)).content
希望有人能给我一个样品


提前感谢您

假设您想使用 您的conf文件如下所示:

[user.auth]
username = my
password = password
username = config.get('user.auth', 'username')
password = config.get('user.auth', 'password')
在代码中,您应该这样使用它:

import configparser


config = configparser.ConfigParser()
config.read("C:\myconf\defaults.cfg")
然后,您应该获得如下凭证:

[user.auth]
username = my
password = password
username = config.get('user.auth', 'username')
password = config.get('user.auth', 'password')
可能重复的