【发布时间】:2014-01-16 18:59:54
【问题描述】:
我正在尝试生成摘要授权标头以用于 python 测试用例。由于代码库的工作方式,我能够将标题作为字符串获取是很重要的。 这个标题看起来像这样
Authorization: Digest username="the_user", realm="my_realm", nonce="1389832695:d3c620a9e645420228c5c7da7d228f8c", uri="/some/uri", response="b9770bd8f1cf594dade72fe9abbb2f31"
我认为我最好的选择是使用 urllib2 或 requests 库。
使用 urllib2,我已经走到了这一步:
au=urllib2.HTTPDigestAuthHandler()
au.add_password("my_realm", "http://example.com/", "the_user", "the_password")
但我无法从中获取标题。
有了请求,我已经走到了这一步:
requests.HTTPDigestAuth("the_user", "the_password")
但是当我尝试在请求中使用它时,我在设置领域时遇到错误,我不知道该怎么做
【问题讨论】:
标签: python urllib2 python-requests digest-authentication