python urllib2和ntlm在响应htm中获取“<h1>移动的对象</h1>”

2024-09-29 18:32:52 发布

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

我正在使用ntlm访问使用windows身份验证的内部服务器。我尝试访问的url一直在重定向。这是我的代码:

import urllib2
from ntlm import HTTPNtlmAuthHandler
import cookielib

user = r'Domain\username'
password = "password"

url = r"http://cmsll.jvservices.com/Livelink/"

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

cookieJar = cookielib.CookieJar()

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

url = r"http://cmsll.jvservices.com/Livelink/livelink.exe?func=ll&objId=87167&objAction=runReport&inputLabel1_ID=118163&inputLabel1_Name=%22Lastname%2C+Firstname+%28domain\username%29%22&inputLabel2=D%2F2013%2F5%2F21%3A0%3A0%3A0&inputLabel2_dirtyFlag=1&inputLabel2_month=5&inputLabel2_day=21&inputLabel2_year=2013&inputLabel2_hour=13&inputLabel2_minute=53&inputLabel2_second=0&inputLabel2_ampm=0&inputLabel3=D%2F2014%2F5%2F21%3A0%3A0%3A0&inputLabel3_dirtyFlag=0&inputLabel3_month=5&inputLabel3_day=21&inputLabel3_year=2014&inputLabel3_hour=0&inputLabel3_minute=0&inputLabel3_second=0&inputLabel3_ampm=0>"

# retrieve the result
req = urllib2.Request(url)
req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0 FirePHP/0.7.4')

response = urllib2.urlopen(req)
print(response.read())

输出如下:

^{pr2}$

响应html不是我想要的。我尝试手动跟踪这个重定向,它给了我另一个重定向。我要怎么做才能让它像这样重新定向?在


Tags: theimporturlpasswordopenerurllib2req重定向
1条回答
网友
1楼 · 发布于 2024-09-29 18:32:52

这可能是因为您在管理页面中设置了“偏移时区”GetTZ“的意思是“得到时区”。要停止它,请取消选中每个服务器/安装实例上的“修改日期和时间”框。这不是整个系统的设置。在

相关问题 更多 >

    热门问题