【问题标题】:HTTP Authentication headers with no "realm"没有“领域”的 HTTP 身份验证标头
【发布时间】:2013-07-04 14:21:21
【问题描述】:

以下代码有效,但即使 response 后面有一个文件实例也没有输出

import urllib2
from ntlm import HTTPNtlmAuthHandler

user = 'id'
password = "Password"
url = "http://abc.def.ghij:3080"

passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, url, user, password)
# create the NTLM authentication handler
auth_NTLM = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(passman)

# create and install the opener
opener = urllib2.build_opener(auth_NTLM)
urllib2.install_opener(opener)

# retrieve the result
response = urllib2.urlopen("http://abc.def.ghij:3080")
print response.read()
print response.headers

标题响应:

    Cache-Control: private

Content-Length: 0

Location: /index.epx

Server: Microsoft-IIS/7.5

X-AspNet-Version: 4.19

Persistent-Auth: true

X-Powered-By: ASP.NET

Date: Thu, 04 Jul 2013 15:30:03 GMT

Connection: close

但是print response.read 没有给出任何内容:O

【问题讨论】:

    标签: python python-2.7 http-headers urllib2 urllib


    【解决方案1】:
    WWW-Authenticate: Negotiate
    WWW-Authenticate: NTLM
    

    问题是您的网络服务器正在请求 NTLM 身份验证,因此它不会接受 BasicAuth。在发送请求时使用 NTML 身份验证或更改您的网络服务器配置以允许基本身份验证。

    不要使用 BasicAuth,因为它通过网络以明文形式发送用户/密码。最低安全是 DigestAuth 或 NTLM 或 GS​​SNegotiate auth。

    【讨论】:

    • 基本身份验证可以通过安全连接 (SSL/TLS) 接受,但我同意摘要更好。但是,我仍然会通过安全连接保留 Digest,因为它依赖于 MD5,它有几个已证明的缺陷。顺便说一句,我收集了Microsoft don't recommend NTLM any more。从安全角度来看,最好的选择可能是用于身份验证的客户端证书,但这对用户来说可能很繁琐。
    • @Webmaster at www.dekh 我按照你的建议实现了它的工作,但我在这里遇到了奇怪的问题......请查看编辑后的问题!
    猜你喜欢
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-12
    相关资源
    最近更新 更多