相关疑难解决方法(0)

使用Python和urllib2进行Windows身份验证

我想从需要我的Windows用户名和密码的网页上获取一些数据.

到目前为止,我有:

opener = build_opener()
try:
    page = opener.open("http://somepagewhichneedsmywindowsusernameandpassword/")
    print page
except URLError:
    print "Oh noes."
Run Code Online (Sandbox Code Playgroud)

这是urllib2支持的吗?我找到了Python NTLM,但这需要我输入我的用户名和密码.有没有办法只是以某种方式获取身份验证信息(例如,如果我改变了network.automatic-ntlm-auth.trusted-uris设置,就像IE一样,或Firefox ).

在msander的回答之后编辑

所以我现在得到了这个:

# Send a simple "message" over a socket - send the number of bytes first,
# then the string.  Ditto for receive.
def _send_msg(s, m):
    s.send(struct.pack("i", len(m)))
    s.send(m)

def _get_msg(s):
    size_data = s.recv(struct.calcsize("i"))
    if not size_data:
        return None
    cb = struct.unpack("i", size_data)[0]
    return s.recv(cb)

def sspi_client():
    c = httplib.HTTPConnection("myserver")
    c.connect()
    # Do the auth dance. …
Run Code Online (Sandbox Code Playgroud)

python urllib2

13
推荐指数
2
解决办法
2万
查看次数

标签 统计

python ×1

urllib2 ×1