Note that there are some explanatory texts on larger screens.

plurals
  1. POWindows Authentication with Python and urllib2
    primarykey
    data
    text
    <p>I want to grab some data off a webpage that requires my windows username and password.</p> <p>So far, I've got:</p> <pre><code>opener = build_opener() try: page = opener.open("http://somepagewhichneedsmywindowsusernameandpassword/") print page except URLError: print "Oh noes." </code></pre> <p>Is this supported by urllib2? I've found <a href="http://code.google.com/p/python-ntlm/" rel="noreferrer">Python NTLM</a>, but that requires me to put my username and password in. Is there any way to just grab the authentication information somehow (e.g. like IE does, or Firefox, if I changed the <code>network.automatic-ntlm-auth.trusted-uris</code> settings).</p> <h1>Edit after msander's answer</h1> <p>So I've now got this:</p> <pre><code># 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." </code></pre> <p>which is pretty well ripped from <code>socket_server.py</code> (see <a href="http://lists.adullact.net/pipermail/atelier-dev-commits/2005-August/000316.html" rel="noreferrer">here</a>). But I get an error 400 - bad request. Does anyone have any further ideas?</p> <p>Thanks,</p> <p>Dom</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload