任何人都可以帮助我使用下面的 python 代码吗?这是一些开源,我为自己的使用做了一些修改。我正在尝试从运行 NTLM 身份验证的 Windows 服务器访问网页。起初我的问题是保持持久连接,这样我就不会收到 http 401 错误。现在我已经解决了这个问题,但是发生的情况是我收到一个 http 302 重定向错误以及一个在响应的 set-cookie 中发回的 cookie。因此我添加了一个 cookie 处理程序,但这并没有做任何事情。此外,从服务器返回的“位置”字段包含我首先提交的原始 URL。我不明白这个。为什么从服务器发回用于重定向的位置字段与我提交的 URL 完全相同?!
import urllib2
import httplib, socket
import cookielib
import ntlm
from ntlm import ntlm
class AbstractNtlmAuthHandler:
httplib.HTTPConnection.debuglevel = 1
url1 = ""
def __init__(self, password_mgr=None):
if password_mgr is None:
password_mgr = HTTPPasswordMgr()
self.passwd = password_mgr
self.add_password = self.passwd.add_password
def http_error_authentication_required(self, auth_header_field, req, fp, headers):
auth_header_value = headers.get(auth_header_field, None)
if auth_header_field:
if 'ntlm' in auth_header_value.lower():
if auth_header_value is not None and …Run Code Online (Sandbox Code Playgroud)