Python无法对libhttp2进行身份验证

2024-05-18 17:52:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个经过身份验证的资源,需要域、用户名和密码进行身份验证。 Python的urllib2提供了realm,而我没有找到httplib2的任何规定。 下面是示例代码, 使用urllib2:

  auth_handler = urllib2.HTTPBasicAuthHandler()
  auth_handler.add_password("Protected",
                          uri="http://" + url,
                          user=username,
                          passwd=password)
  opener = urllib2.build_opener(auth_handler)
  urllib2.install_opener(opener)

  try :
     data = urllib2.urlopen(url, None, timeout).read()

这里“Protected”是身份验证所需的领域。在

现在看看httplib2:

^{pr2}$

对于httplib2,我没有找到任何提供域字符串进行身份验证的规定。在

有没有办法在httplib2中添加这个领域字符串??在


Tags: 字符串auth身份验证url密码password资源opener
1条回答
网友
1楼 · 发布于 2024-05-18 17:52:34

如果httplib2不是必须的,那么使用^{}就变得微不足道了:

requests.get('http://www.example.com/', auth=('user', 'pass'))

相关问题 更多 >

    热门问题