Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatic NTLM with python on Windows

How can I use automatic NTLM authentication from python on Windows?

I want to be able to access the TFS REST API from windows without hardcoding my password, the same as I do from the web browser (firefox's network.automatic-ntlm-auth.trusted-uris, for example).

like image 844
liorda Avatar asked Dec 23 '22 15:12

liorda


1 Answers

I found this answer which works great for me because:

  1. I'm only going to run it from Windows, so portability isn't a problem
  2. The response is a simple json document, so no need to store an open session

It's using the WinHTTP.WinHTTPRequest.5.1 COM object to handle authentication natively:

import win32com.client
URL = 'http://bigcorp/tfs/page.aspx'    
COM_OBJ = win32com.client.Dispatch('WinHTTP.WinHTTPRequest.5.1')
COM_OBJ.SetAutoLogonPolicy(0)
COM_OBJ.Open('GET', URL, False)
COM_OBJ.Send()
print(COM_OBJ.ResponseText)
like image 165
liorda Avatar answered Dec 28 '22 10:12

liorda