我想从需要我的 Windows 用户名和密码的网页中获取一些数据。
到目前为止,我有:
opener = build_opener()
try:
page = opener.open("http://somepagewhichneedsmywindowsusernameandpassword/")
print page
except URLError:
print "Oh noes."
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.
ca = sspi.ClientAuth("NTLM", win32api.GetUserName())
data = None
while 1:
err, out_buf = ca.authorize(data) # error 400 triggered by this line
_send_msg(c.sock, out_buf[0].Buffer)
if err==0:
break
data = _get_msg(c.sock)
print "Auth dance complete - sending a few encryted messages"
# Assume out data is sensitive - encrypt the message.
for data in "Hello from the client".split():
blob, key = ca.encrypt(data)
_send_msg(c.sock, blob)
_send_msg(c.sock, key)
c.sock.close()
print "Client completed."
这是很好的撕毁socket_server.py
(见这里)。但我收到错误 400 - 错误请求。有没有人有任何进一步的想法?
谢谢,
多姆