Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python requests NTLM without password [duplicate]

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 600
liorda Avatar asked Aug 02 '17 06:08

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 69
liorda Avatar answered Oct 14 '22 04:10

liorda